eloquent javascript 2nd edition chapter 2 Program Structure
今回からは気になるところだけメモしていくことにしました。
whileとdo-whileのちがい
条件aに関わらずdo-whileは最低1回は実行されてしまう。
**以下エクササイズのネタバレありです**
Exercise
Looping a Triangl
Write a loop that makes seven calls to
console.log
to output the following triangle:# ## ### #### ##### ###### #######
FizzBuzz
Write a program that uses
console.log
to print all the numbers from 1 to 100, with two exceptions. For numbers divisible by 3, print"Fizz"
instead of the number, and for numbers divisible by 5 (and not 3), print"Buzz"
instead.When you have that working, modify your program to print
"FizzBuzz"
, for numbers that are divisible by both 3 and 5 (and still print"Fizz"
or"Buzz"
for numbers divisible by only one of those).
I wrote a simple for-loop.
Then added if expression.
But if I ran this, the result was below.
What was wrong?
I forgot to add else?
It showed like below.
Almost there!!
The only thing was 'Fizz' should be appeared, when n%3 ===0.
Spoiler alert!I saw the hint.
It said use || operator!!
This is my final answer.