
Cory N. answered 12/11/22
Software Engineer - Web Development
Hello!
This will vary a bit based on the language you use, lets first write this in PsuedoCode
Declare an array, assign each month in order to the array.
Loop through the array, print month name and the corresponding number.
IN Javascript:
// Delcare a variable using let, assign an array containing strings of each month.
let months = ['january', 'febuary', 'march', 'april', .... etc]
// Loop through the array starting at position zero(most languages arrays start at zero, not 1)
// continue doing that until you reach the end of the array, position 11. each time you loop, add 1 to the position.
for(let loopposition = 0; loopposition < months.length, loopposition++) {
console.log(loopposition + 1, months[loopposition]
// above we print a number equal to the loop position plus 1 - IE 1, 2 , 3, 4 .... Then it prints the array value of the current loopposition which will be 'january', 'febuary', 'march', 'april' ...... etc
}
Best of luck!