0

Trying to solve skipping 13 in JavaScript

Many tall buildings, including hotels, skip the number 13 when numbering floors -- often going from floor 12 to floor 14. It is thought that the number 13 is unlucky. Write a program that will number 15 rooms starting from 1, skipping the number 13. Output to the console each room number in separate line.

11th May 2021, 4:28 PM
Simisola Osinowo
Simisola Osinowo - avatar
16 ответов
+ 6
var countOfRooms = 15; // Your code here for (i=1;i<=16;i++){ if(i==13){ continue } console.log(i) } This worked for me ✌
17th Jun 2021, 5:37 PM
Razvan Roşu
Razvan Roşu - avatar
12th May 2021, 2:43 PM
Simisola Osinowo
Simisola Osinowo - avatar
+ 1
I think this is the correct way. Try this. for (i=1; i<=countOfRooms+1; i++){ if(i==13) { continue; } console.log(i); }
30th Jan 2022, 5:17 PM
Jason Chong
Jason Chong - avatar
0
Hi! For better help for you, Please, show us your code attempt! Thx!
11th May 2021, 4:36 PM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
0
var countOfRooms = 15; // Your code here for (i=1; i<=15; i++){ if (i==13){ comtinue; } document.write(i+"<br/>"); }
11th May 2021, 4:38 PM
Simisola Osinowo
Simisola Osinowo - avatar
0
easy as heck, just print ALL OF THEM and skip 13th number! AND YOUR TEACHER WILL APPRECIATE IT! joke aside. attempt it yourself. edit: Simisola Osinowo oh bruh, you misspelled continue aand you didn't used countOfRooms variable in the for loop.
11th May 2021, 4:38 PM
Rellot's screwdriver
Rellot's screwdriver - avatar
0
comtinue -> continue
11th May 2021, 4:39 PM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
0
Now it's saying document not defined
11th May 2021, 4:46 PM
Simisola Osinowo
Simisola Osinowo - avatar
0
Instead of "document.write" -> insert "console.log"
11th May 2021, 4:51 PM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
0
Done that var countOfRooms = 15; // Your code here for (i=1; i<=15; i++){ if (i==13){ continue; } console.log(i); } But now it does not print 16
11th May 2021, 4:55 PM
Simisola Osinowo
Simisola Osinowo - avatar
0
so you have only 15 rooms. at the very beginning, the variable is assigned the value 15
11th May 2021, 5:02 PM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
0
Simisola Osinowo var I is 1 instead of 0
12th May 2021, 6:01 PM
Habeeb Tijani
Habeeb Tijani - avatar
0
This solution works for me for any number of rooms (I tried to make it reusable) var countOfRooms = 15; // Your code here if(countOfRooms >= 13){ for(var i = 1; i <= countOfRooms + 1; i++){ if(i == 13){ continue; } else{ console.log(i) } } } else{ for(var i = 1; i <= countOfRooms; i++){ console.log(i); } } ---------------------------------------------------------------------------------------------------------- Otherwise for this question specifically: var countOfRooms = 15; // Your code here for(var i = 1; i <= countOfRooms + 1; i++){ if(i == 13){ continue; } else{ console.log(i); } } edit: added reusable method and easier readability
22nd Sep 2021, 5:33 AM
Andy McCoy
Andy McCoy - avatar
0
Tijanihabeeb it needs to be 1 otherwise you'll end up printing a room number of '0' If you want it to make the loop more reusable for any number of rooms, you'll need to increase the original var For example: for (n = 1; n <= countOfRooms; n++) { if (n == 13) { countOfRooms++ continue; } console.log(n); }
29th Mar 2022, 9:30 PM
Stephen K
0
var countOfRooms = 15; // Your code here for (i=1;i<=16;i++){ if(i==13){ continue } console.log(i) } //I hope, This will helful for the beginner .
5th Nov 2022, 7:53 PM
Be Rain
Be Rain - avatar
0
var countOfRooms = 15; // Your code here for (let countOfRooms=1; countOfRooms<17; countOfRooms++) { if(countOfRooms == 13) { continue; } console.log(countOfRooms); } This worked for me.
15th Nov 2022, 10:33 AM
Ionut Laurian Iscru
Ionut Laurian Iscru - avatar