-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathfunctions-quiz.txt
More file actions
72 lines (60 loc) · 1.21 KB
/
functions-quiz.txt
File metadata and controls
72 lines (60 loc) · 1.21 KB
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
/* Intro to JavaScript QUIZ[SOLVED]
Chapter - Functions
Total Quiz-6
*/
Quiz-1
Declare a function called laugh() that returns "hahahahahahahahahaha!".
Print the value returned from the laugh() function to the console.
Code:
function laugh() {
return "hahahahahahahahahaha!";
}
console.log(laugh());
Output:
hahahahahahahahahaha!
Quiz-2
Write a function called laugh() that takes one parameter,
num that represents the number of "ha"s to return.
Code:
function laugh(num) {
var ha='';
for(var i=0;i<num;i=i+1) {
ha+="ha";
string=ha+"!";
}
return string;
}
console.log(laugh(3));
Output:
hahaha!
Quiz-3
Create a function called buildTriangle()
that will accept an input (the triangle at its widest width) and will build a triangle.
Code:
function makeLine(length) {
var line = "";
for (var j = 1; j <= length; j++) {
line += "* "
}
return line + "\n";
}
function buildTriangle(num){
var buildtriangle="";
for (var i=1;i<=num;i++){
var make=makeLine(i);
buildtriangle += make;
}
return buildtriangle;
}
console.log(buildTriangle(10));
Output:
*
* *
* * *
* * * *
* * * * *
* * * * * *
* * * * * * *
* * * * * * * *
* * * * * * * * *
* * * * * * * * * *