+ 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
2 Answers
+ 3
this?
let floors = 53 //test value
for(let f=1; f<=floors; f++)
if(f%5==0) console.log(f)
+ 1
//The corrected code:
for (floors; floors <= 0; floors++){
if(floors % 5 == 0){
console.log(floors);}
}
//Here, the code increases floors instead of decreasing