-
Notifications
You must be signed in to change notification settings - Fork 0
/
04-EJS-Ch2-exercises.js
86 lines (76 loc) · 1.92 KB
/
04-EJS-Ch2-exercises.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/*
* Complete the exercises below.
*
* You can run this file in your command line by using node:
*
* $ node ./04-EJS-Ch2-exercises.js
*
* The `console.log()` function will work as expected.
*/
/*
* LOOPING A TRIANGLE
*
* Write a loop that makes seven calls to console.log
* to output the following triangle:
*
* #
* ##
* ###
* ####
* #####
* ######
* #######
*
* It may be useful to know that you can find the length of
* a string by writing .length after it.
*
* var abc = "abc";
* console.log(abc.length);
* // → 3
*
*/
console.log("\n== Triangle exercise ==\n")
// Your code here.
/*
* 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).
*/
console.log("\n== FizzBuzz exercise ==\n")
// Your code here.
/*
* CHESS BOARD
*
* 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 chess board.
*
* Passing this string to console.log should show something
* like this:
*
* # # # #
* # # # #
* # # # #
* # # # #
* # # # #
* # # # #
* # # # #
* # # # #
*
* When you have a program that generates this pattern,
* define a variable size = 8 and change the program so that
* it works for any size, outputting a grid of the given width
* and height.
*/
console.log("\n== Chess board exercise ==\n")
// Your code here.