book excecise 1 - looping a triangle
var stars = “”;
var counter = 0
while (counter <8) {
console.log(stars);
stars = stars + “#”;
counter++;
}
FizzBuzz
for (var number = 0; number < 100; number++){
if (number % 3==0 && number % 5 == 0){console.log(“FizzBuzz”)
}
else if (number % 3 == 0) {console.log(“Fizz”)
}
else if(number % 5 == 0) {console.log(“Buzz”)
}
else {console.log(number)
}
}
Chequer board
I got myself in a right mess with this one, couldnt really figure it out in the end. At first I made a script that made the first line, which was all good. Then trying to implement it onto multiple lines I tied myself in nots going round in circles, I had to look up the answer in the end but this was my incorrect effort by the end -
var boardSize = 8
var showBoard = “”
var hash = “#”
var space = " "
for (var xCounter = 0; xCounter < boardSize; xCounter++){
if (xCounter % 2 == 0){
for (var yCounter = 0; yCounter < boardSize; yCounter++){
if (yCounter % 2 == 0){(showBoard=showBoard+space)
}
else {(showBoard=showBoard+hash)}
}
else {for (var yCounter = 0; yCounter < boardSize; yCounter++){
if (yCounter % 2 == 0){(showBoard=showBoard+hash)
}
else {(showBoard=showBoard+space)}
}
}
}