//Looping a Triangle Exercise
var poundSign = “#”;
for (counter = 1; counter < 8; counter = counter + 1)
{
for (counter2 = 0; counter2 < counter; counter2 = counter2 + 1)
{console.log(poundSign);
}
console.log("
");
}
/*
FizzBuzz
Write a program that uses console.log to print all
the numbers from 1 to 100, with two exceptions. For numbers
divisible by 3, print “Fizz” instead of the number, and for numbers
divisible by 5 (and not 3), print “Buzz” instead.
When you have that working, modify your program to print
“FizzBuzz” for numbers that are divisible by both 3 and 5
(and still print “Fizz” or “Buzz” for numbers
divisible by only one of those).
*/
//Part 1 (For numbers divisible by 3 print “Fizz”, and for divisible by 5, print “Buzz”
var numberLimit = 101;
// Add For Loop for running through numbers 1 thru 100
//for each number, check is the number is dvisible by 3
//if divisible by 3 print “Fizz”
//else if divisible by 5 print “Buzz”
//else print the number.
for (counter = 1; counter < numberLimit; counter++)
{
if (counter % 3 == 0)
{
console.log(“Fizz”);
}
else if (counter % 5 == 0)
{
console.log(“Buzz”);
}
else {
console.log(counter);
}
}
// ***********************************************//
//Part 2 of Fizz Buzz **
var numberLimit = 101;
// Add For Loop for running through numbers 1 thru 100
//for each number, check is the number is dvisible by 3
//if divisible by 3 print “Fizz”
//else if divisible by 5 print “Buzz”
//else print the number.
for (counter = 1; counter < numberLimit; counter++)
{
if ((counter % 3 == 0) && (counter % 5 == 0))
{
console.log(“FizzBuzz”);
}
else if (counter % 3 == 0)
{
console.log(“Fizz”);
}
else if (counter % 5 == 0)
{
console.log(“Buzz”);
}
else {
console.log(counter);
}
}
/*
Chessboard
Write a program that creates a string that represents an 8×8 grid,
using newline characters to separate lines. At each position of the
grid there is either a space or a “#” character. The characters should
form a chessboard.
Passing this string to console.log should show something like this:
When you have a program that generates this pattern, define a binding size
= 8 and change the program so that it works for any size, outputting a grid
of the given width and height.
*/
//Gridsize is the size of the checkboard grid
//Print mode controls whether a “#” is printed or a blank { mode = 0 is blank, mode = 1 is a ‘#’}
//Create For Loop for overall Grid
//Create a For Loop within the For loop above to alternate prints of # and bank spaces
var width = 8
var height = 8
var mode = 0
var grid = “”; //holder for the Grid
for (counter = 1; counter < height + 1; counter ++)
{
for (counter2 = 1; counter2 < width + 1; counter2++)
{
if (mode == 0)
{
grid = grid + " ";
mode = 1;
}
else if (mode == 1)
{
grid = grid + “#”;
mode = 0;
}
}
if (mode == 0)
{mode = 1; }
else
{mode = 0; }
grid = grid + ‘\n’;
}
console.log(grid);