I am going through codeacademys JavaScript tutorials as i am new to it. The tutorial asks for the following:
Print out the numbers from 1 - 20.
The rules:
I don't know Javascript, but I know some Python and I've come across the same problem. Maybe this can help. I'm sure someone can just translate this for Javascript.
Here's the original problem: Loop through the numbers between 1 and 20. If a number is divisible by 3, print Hip. If the number is divisible by 7, print “Hooray”.
Here's the code for python for a similar problem:
for numbers in range(1,21):
if numbers % 3 !=0 and numbers % 7 != 0:
print(numbers)
if numbers % 3 == 0:
print("Hip")
if numbers % 7 == 0:
print("Hooray")
Here's the output:
1 2 Hip 4 5 Hip Hooray 8 Hip 10 11 Hip 13 Hooray Hip 16 17 Hip 19 20