programming with javascript coursera week 1 quiz answers
Knowledge check: Welcome to Programming
1. What is the data type of the value "Hello, World"?
- string
- number
- boolean
2. What is the data type of the value true ?
- string
- number
- boolean
3. What is the % operator?
- The modulus operator
- The division operator
- The concatenation operator
4. What happens when you use the + operator on two strings?
- They get joined into a single string
- You can’t use the + operator on two strings
5. What is the operator symbol && represent in JavaScript?
- The logical OR operator
- The logical AND operator
- The logical NOT operator
6. What happens when you use the + operator on a string and a number?
- Nothing – you can’t use the + operator on different data types
- They get joined together as if both of them were strings
Knowledge check - Conditionals and loops
8. Based on the following code, what will print out when the variable i has the value 3 ?
if(i < 5) {
console.log("Hello");
} else {
console.log("Goodbye");
}
- Hello
- Goodbye
9. Based on the following code, what will print out when the variable i has the value 1 ?
if(i == 0 && i == 1) {
console.log("Hello");
} else {
console.log("Goodbye");
}
- Hello
- Goodbye
10. How many times will the following code print the word 'Hello'?
for (i = 0; i < 2; i++) {
console.log("Hello");
}
- 1
- 2
- 3
- 4
11. How many times will the following code print the word 'Hello'?
var i = 0;
while(i < 3) {
console.log("Hello");
i++;
}
- 1
- 2
- 3
- 4
12. How many times will the following code print the word 'Hello'?
for (i = 0; i < 2; i++) {
for (var j = 0; j < 3; j++) {
console.log("Hello");
}
}
- 2
- 3
- 4
- 6
13. Based on the following code, what will print out when the variable i has the value 7 ?
if(i <= 5) {
console.log("Hello");
} else if(i <= 10) {
console.log("Goodnight");
} else {
console.log("Goodbye");
}
- Hello
- Goodnight
- Goodbye
14. Based on the following code, what will print out when the variable i has the value 3 ?
switch(i) {
case 1: console.log("Hello");
break;
case 2:
console.log("Goodnight");
break;
case 3:
console.log("Goodbye");
break;
}
- Hello
- Goodnight
- Goodbye
15. Based on the following code, what will print out when the variable i has the value 3 ?
if(i == 2 || i == 3) {
console.log("Hello");
} else {
console.log("Goodbye");
}
- Hello
- Goodbye
Module quiz: Introduction to JavaScript
16. You can run JavaScript in a web browser's devtools console.
- true
- false
17. Which of the following are valid comments in JavaScript? Select all that apply.
- \ Comment 1
- // Comment 2
- ##
## Comment 3
## - /*
* Comment 4
*/
18. Which of the following are valid data types in JavaScript? Select all that apply.
- string
- numbers
- booleans
- null
19. Which of the following is the logical AND operator in JavaScript?
- &
- &&
- ||
- |\
20. Which of the following is the assignment operator in JavaScript?
- =
- ==
- ===
21. How many times will the following code print the word 'Hello'?
for(var i = 0; i <= 5; i++) {
console.log("Hello");
}
- 4
- 5
- 6
22. What will print out when the following code runs?
var i = 3;
var j = 5;
if(i == 3 && j < 5) {
console.log("Hello");
} else {
console.log("Goodbye");
}
- Hello
- Goodbye
- Nothing
23. What will print out when the following code runs?
var i = 7;
var j = 2;
if(i < 7 || j < 5) {
console.log("Hello");
} else {
console.log("Goodbye");
}
- Hello
- Goodbye
- Nothing
24. The result of !false is:
- true
- undefined
25. What does the operator symbol || represent in JavaScript?
- The logical OR operator
- The logical NOT operator
- The logical AND operator