FIZZBUZ
function fizzbuz (target) {
for(var i=1; i <=target; i++) {
linestr =i;
if (i%3 == 0) {
linestr = ‘fizz’;
if (i%5 == 0) {
linestr = ‘fizzbuz’;
}
} else if (i%5 == 0) {
linestr = ‘buzz’;
}
console.log(linestr)
}
return ‘done’.
}
fizzbuz ( )
“done.”
fizzbuz (16)
==================================================
Looping a tringle
function recursetree (pattern,endlevel) {
console.log (pattern);
if (pattern.length < end level) {
recursetree (pattern + ‘#’, endlevel);
}
}
recursetree (’#’,7)
=============================================
Chessboard
function chessboard ( ) {
var rankest = undefined;
for (var row = 1; row <= 8; row++) {
rankest = ’ ';
for (var col = 1; col <= 8; col ++) {
if ((row + col)%2 == 0) {
rankest += ’ . ’ ;
} else {
rankest += ‘#’ ;
} //switch colors
} // traverse cols
console.log (rankstr)
} // traverse rows
return ‘done.’
} //chessboard ( )
chessboard ( )