+ 1

Nearest restaurant code printing numbers in opposite order?(JavaScript)

Hey guys. I've generally been able to figure out all the challenges in the course so far but this one has me puzzled. I have the code 90% right I think because it prints the right numbers which it is supposed to output all floors of the hotel that are multiples of 5. The problem is it wants the numbers to go smallest number first ending with biggest but my output is the opposite and I can't figure out why that is. Any help is appreciated! My code: for (floors; floors > 0; floors--){ if(floors % 5 == 0){ console.log(floors);} } Example: User enters 20 My output: 20 15 10 5 Expected Output: 5 10 15 20

4th Nov 2023, 10:52 PM
Jordan N
2 odpowiedzi
+ 3
this? let floors = 53 //test value for(let f=1; f<=floors; f++) if(f%5==0) console.log(f)
5th Nov 2023, 2:08 AM
Bob_Li
Bob_Li - avatar
+ 1
//The corrected code: for (floors; floors <= 0; floors++){ if(floors % 5 == 0){ console.log(floors);} } //Here, the code increases floors instead of decreasing
5th Nov 2023, 12:18 AM
Annihilate
Annihilate - avatar