« Back to Main Page

Coding Challenge: Loops Challenge

From Bold Idea Knowledgebase

View code challenge

Solving the "Loops Challenge" demonstrates a students' understanding of counting loops , arrays , and for-of loops .

Requirements

  • The first part of the program must use a counting loop to output the square of every number from 0 to 10
  • The second part of the program must use a for...of loop to output "Have a _____ day" for each of the adjectives in the array.

Example Solution

/**
 * 1. Use a counting loop to output the square of every
 *    number from 0 to 10.
 */

for (let n=0; n<11; n++) {
    console.log(n * n);
}


/**
 * 2. Use a for...of loop to output "Have a ______ day"
 *    for each of the acjectives (using console.log)
 */

let adjectives = ["fantastic", "great", "super", "fun"];

for (let word of adjectives) {
    console.log(`Have a ${word} day`);
}