

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Difficulty: 5
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
The break keyword can be used to break out of a loop early.
for (let i = 0; i < 10; i++) {
if (i === 3) {
break;
}
console.log(i);
}
// Prints:
// 0
// 1
// 2
You can omit the loop condition in a for loop to create an intentional infinite loop and then use break to exit, for example:
for (let i = 0; ; i++) {
if (i === 3) {
break;
}
console.log(i);
}
No matter the end condition, when a break statement is encountered, the loop will exit immediately.
Textio can send as many messages as the budget allows. We want to find out how many messages we can send before the total cost of those messages would exceed the given budget.
Complete the maxMessagesWithinBudget function. It should use an infinite loop to keep track of the totalCost and a count of the messages sent.