Javascript Question for loops | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula gr√°tis
+ 1

Javascript Question for loops

This is the code I wrote to list all hotel rooms in the console for a Sololearn practice project using console.log and using a new line for each hotel room. I should remove hotel room 13 from the loop. So far so good, but I get an error message every time. I can't get a line break with + '<br/>' or without this addition. I am really desperate. On the internet I find that the br function only exists for document.write functions var countOfRooms = 15; var i = 0; for (i = 0; i <= countOfRooms; i++) { if (i == 13) { continue; } console.log(i); //console.log(i + '\n'); both Versions dont work //console.log(i + '<br/>'); both Versions dont work }

3rd Mar 2024, 4:41 PM
Deniz Lier
Deniz Lier - avatar
2 Respostas
+ 3
In the console, you can achieve a line break using `\n`. The issue might be with how you're viewing the output. If you're using a browser console, HTML tags like `<br/>` won't work. Your code with `\n` should work: ```javascript var countOfRooms = 15; var i = 0; for (i = 0; i <= countOfRooms; i++) { if (i == 13) { continue; } console.log(i + '\n'); } ``` Make sure to check the console output, and if you're using a browser console, the line breaks should be visible when you inspect the console or use `console.log` within a browser environment.
3rd Mar 2024, 5:08 PM
Knight
Knight - avatar
+ 1
Describe the task, or give an example of the intended output.
3rd Mar 2024, 5:12 PM
Solo
Solo - avatar