We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

While

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!

Assignment

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.