DEV Community

loading...

Discussion on: Daily Challenge #40 - Counting Sheep

Collapse
danielsclet profile image
Daniel Santos

JavaScript

function cs(n) {
    if (typeof n != "number" && n < 0) return `${n} is not a valid number`;

    let text = "";

    for(let x = 0; x < n; x++) {
        text += `${x} sheep... `
    }

    return text;
}

cs(3) // 0 sheep... 1 sheep... 2 sheep...