samedi 17 mars 2018

Where i make mistake here?

Hello everyone i have a problem with my code and i'm not sure how to do this , i need to write code that draw this in console:

Draw '*' in every even number

For that i need to use nested loops.

So far i have only this:

var n = 5;
var stars = '';
for (var i = 1; i <= n; i++) {
var starsline = '';
for (var j = 1; j <= n; j++){
    console.log(i + j)
} if ( i % 2 === 0){
    starsline += '2';
} else {
    starsline += '1'
}
stars += starsline;
}
console.log(stars);

This numbers 2 and 1 are only to check if the number is even or odd.

Aucun commentaire:

Enregistrer un commentaire