How to solve this problem?
-
Hello! There is a problem that should be solved through the for loop. But I don't understand how to solve it yet:
Suppose you have an array with the names of the months. Let the variable month store the number of the current month, for example, 10. Use a loop to print all months, and print the current month in italics.JavaScript Eliot Harmon, Jul 18, 2019 -
let months = [1,2,3,4,5,6,7,8,9,10,11,12]
let month = 10
let ul = document.createElement('ul')
for(let i = 0; i<months.lenght; i++) {
let li = document.createElement("li")
li.innerHTML = i
ul.appendChild(li)
if(i+1 === 10) li.classList.app('cursive')
}
document.body.appendChild(ul)Anonymous -
you iterate over all LETTERIAL months, when i = 10-1 (it is accepted to iterate over from scratch), you display the month in italics.
const n =10;
for (let i = 0; i < 12; i++) {
//просто вывод
if(i === (n-1)){
//Вывод курсивом
}
}Anonymous
2 Answers
Your Answer
To place the code, please use CodePen or similar tool. Thanks you!