If-then-else? How about picking up another technique, the ternary operator?
while (i < 4) {
let message = (i ==3) ? "Happy Birthday dear " + name + "," : "Happy Birthday to you. ";
document.write(message);
i = i + 1;
}
Which isn't the end of ways to refactor this. You could get rid of the temporary variable by having the ternary inside the document.write(), and you could change the while loop to a for loop. There's almost never only one way to do something when it comes to programming.
If-then-else? How about picking up another technique, the ternary operator?
while (i < 4) {
let message = (i ==3) ? "Happy Birthday dear " + name + "," : "Happy Birthday to you.
";
document.write(message);
i = i + 1;
}
Which isn't the end of ways to refactor this. You could get rid of the temporary variable by having the ternary inside the document.write(), and you could change the while loop to a for loop. There's almost never only one way to do something when it comes to programming.
This is great! Thanks for building on this code and showing me another way to write it! I'm learning so much.