Loops: Is this the best way to write them?


#1

For lesson 7-11, I wrote the following code. I know it works, but is the code as clean as it could be? For example, am I missing any semicolons, or do I have too many? Does my grammar match the standards?

Thanks! :monkey:
Adam

for (var number = 200; number >= 0; number = number - 10) {
    console.log(number)
}

var fruit = prompt("Name a fruit.");
while (fruit !="banana") {
    alert("You didn't say banana!");
    fruit = prompt("Name a fruit.");
}

do {
    var who = prompt ("knock knock...");
}
while (who != "who's there?");

#2

console.log(number)

after lines like this you would use a semicolon and the:

number = number - 10

could be shortend to number-=10 but overall it seems to be ok. Used while loops that actually make sense. So I'd say its ok.