

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Difficulty: 3
click for more info
Not enough gems
Cost: 6 gems
1: Loops
incomplete
2: Break
incomplete
3: Continue
incomplete
4: While
incomplete
5: For...in
incomplete
This lesson's interactive features are locked, please to keep using them
Like many other languages, JavaScript has a while loop. It keeps running as long as the condition is true.
const jane = {
name: "Jane",
mom: {
name: "Alice",
mom: {
name: "Lilly",
mom: {
name: "Granny",
},
},
},
};
let currentPerson = jane;
while (currentPerson) {
console.log(currentPerson.name);
currentPerson = currentPerson.mom;
}
console.log("No more ancestors!");
// Jane
// Alice
// Lilly
// Granny
// No more ancestors!
We charge exponentially more money for each consecutive text sent... because we're a greedy SAAS. Don't judge.
The getMaxMessagesToSend calculates how many messages can be sent by a user based on a multiplier and the total amount they have to spend. The first message costs a penny, and each message after that costs the same as the previous message multiplied by the costMultiplier.
There is a bug in the code! The while loop responsible for accumulating the total cost should keep running until the balance runs out, fix it.