All Weeks Programming with JavaScript Quiz Answers
Table of Contents
Programming with JavaScript Week 01 Quiz Answers
Quiz 1: Self review: Declaring variables
Q 1: Did you complete the Declaring variables exercise?
- Yes
- No
Q 2: Are you comfortable with using console.log?
- Yes
- No
Q 3: Are you comfortable using the assignment operator?
- Yes
- No
Quiz: Self Review – Advanced use of operators
Q 1: Did you complete the Advanced use of operators exercise?
- Yes
- No
Q 2: Did you find any part of the exercise on the Advanced Use of Operators difficult?
- Yes
- No
Q 3: Would you say that you are able to explain, in your own words, how logical operators &&, ||, and ! work in JavaScript?
- Yes
- No
Quiz 3: Knowledge check: Welcome to Programming
Q 1: What is the data type of the value “Hello, World”?
- string
- number
- boolean
Q 2: What is the data type of the value true?
- string
- number
- boolean
Q 3: What is the % operator?
- The modulus operator
- The division operator
- The concatenation operator
Q 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
Q 5: What is the operator symbol && represented in JavaScript?
- The logical OR operator
- The logical AND operator
- The logical NOT operator
Q 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
Q 7: What is the value of I after the following code runs?
var i = 7;
i += 1;
i += 2;
- 7
- 8
- 9
- 10
Quiz 7: Knowledge check – Conditionals and loops
Q 1: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
Q 2: 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
Q 3: How many times will the following code print the word ‘Hello’?
for (i = 0; i < 2; i++) {
console.log("Hello");
}
- 1
- 2
- 3
- 4
Q 4: 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
Q 5: 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
Q 6: 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
Q 7: 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
Q 8: 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
Quiz 8: Module quiz: Introduction to JavaScript
Q 1: You can run JavaScript in a web browser’s dev tools console.
- true
- false
Q 2: Which of the following are valid comments in JavaScript? Select all that apply.
Answer: // Comment 2
Q 3: Which of the following are valid data types in JavaScript? Select all that apply.
- string
- numbers
- booleans
- null
Q 4: Which of the following is the logical AND operator in JavaScript?
Answer: &&
Q 5: Which of the following is the assignment operator in JavaScript?
Answer: =
Q 6: How many times will the following code print the word ‘Hello’?
for(var i = 0; i <= 5; i++) {
console.log("Hello");
}
- 4
- 5
- 6
Q 7: 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
Q 8: 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
Q 9: The result of! false is:
- true
- uundefined
Q 10: What does the operator symbol || represent in JavaScript?
- The logical AND operator
- The logical OR operator
- The logical NOT operator
Programming with JavaScript Week 02 Quiz Answer
Quiz 1: Knowledge check: Arrays, Objects and Functions
Q 1: What data type is the variable item?
var item = [];
- Boolean
- Function
- Array
Q 2: What is the value of the result for the following code?
var result = “Hello”.indexOf(‘l’);
- 1
- 2
- 3
- 4
Q 3: What is the length of the clothes array after this code runs?
var clothes = [];
clothes.push('gray t-shirt');
clothes.push('green scarf');
clothes.pop();
clothes.push('slippers');
clothes.pop();
clothes.push('boots');
clothes.push('old jeans');
- 1
- 2
- 3
- 4
Q 4: What value is printed out by the following code?
var food = [];
food.push('Chocolate');
food.push('Ice cream');
food.push('Donut');
console.log(food[1])
- Chocolate
- Ice cream
- Donut
Q 5: How many properties does the dog object have after the following code is run?
var dog = {
color: "brown",
height: 30,
length: 60
};
dog["type"] = "corgi";
- 1
- 2
- 3
- 4
Q 6: In the following function, the variables a and b are known as _______________.
function add(a, b) {
return a + b;
}
- Parameters
- Return Values
Q 7: Which of the following are functions of the Math object?
- random()
- sqrt()
Quiz 2: Knowledge check: Error handling
Q 1: What will be printed when the following code runs?
var result = null;
console.log(result);
- undefined
- null
- 0
Q 2: When the following code runs, what will print out?
try {
console.log('Hello');
} catch(err) {
console.log('Goodbye');
}
- Hello
- Goodbye
Q 3: If you pass an unsupported data type to a function, what error will be thrown?
- RangeError
- SyntaxErrror
- TypeError
Q 4: What will print out when the following code runs?
var x;
if(x === null) {
console.log("null");
} else if(x === undefined) {
console.log("undefined");
} else {
console.log("ok");
}
- null
- undefined
- ok
Q 5: What will print out when the following code runs?
throw new Error();
console.log("Hello");
- Hello
- Nothing will print out
Quiz 3: Module quiz: The Building Blocks of a Program
Q 1: What data type is the variable x?
var x = {};
- Function
- Array
- Object
Q 2: What will be the output of running the following code?
try {
console.log('hello)
} catch(e) {
console.log('caught')
}
- Uncaught SyntaxError: Invalid or unexpected token.
- Caught
Q 3: What value is printed when the following code runs?
var burger = ["bun", "beef", "lettuce", "tomato sauce", "onion", "bun"];
console.log(burger[2]);
- bun
- beef
- lettuce
- tomato sauce
- onion
Q 4: In the following code, how many methods does the bicycle object have?
var bicycle = {
wheels: 2,
start: function() {
},
stop: function() {
}
};
- 1
- 2
- 3
Q 5: When the following code runs, what will print out?
try {
throw new Error();
console.log('Hello');
} catch(err) {
console.log('Goodbye');
}
- Hello
- Goodbye
Q 6: If you mis-type some code in your JavaScript, what kind of error will that result in?
- RangeError
- SyntaxErrror
- TypeError
Q 7: Will the following code execute without an error?
function add(a, b) {
console.log(a + b)
}
add(3, "4");
- Yes
- No
Q 8: What will be printed when the following code runs?
var result;
console.log(result);
- undefined
- null
- 0
Q 9: What will be the output of the following code?
var str = "Hello";
str.match("jello");
- null
- undefined
- empty string
Q 10: What will be the output of the following code?
try {
Number(5).toPrecision(300)
} catch(e) {
console.log("There was an error")
}
- RangeError
- 5
- e
- “There was an error”
Programming with JavaScript Week 03 Quiz Answer
Quiz 1: Knowledge check: Introduction to Functional Programming
Q 1: What will print out when the following code runs?
var globalVar = 77;
function scopeTest() {
var localVar = 88;
}
console.log(localVar);
- 77
- 88
- null
- undefined
Q 2: Variables declared using const can be reassigned.
- true
- false
Q 3: When a function calls itself, this is known as _____________.
- Recursion
- Looping
- Higher-order Function
Q 4: What will print out when the following code runs?
function meal(animal) {
animal.food = animal.food + 10;
}
var dog = {
food: 10
};
meal(dog);
meal(dog);
console.log(dog.food);
- 10
- 20
- 30
- 40
Q 5: What value will print out when the following code runs?
function two() {
return 2;
}
function one() {
return 1;
}
function calculate(initialValue, incrementValue) {
return initialValue() + incrementValue() + incrementValue();
}
console.log(calculate(two, one));
- 1
- 2
- 3
- 4
Quiz 2: Knowledge check: Introduction to Object-Oriented Programming
Q 1: What will print out when the following code runs?
class Cake {
constructor(lyr) {
this.layers = lyr + 1;
}
}
var result = new Cake(1);
console.log(result.layers);
- 1
- 2
- 3
- 4
Q 2: When a class extends another class, this is called ____________.
- Inheritance
- Extension
Q 3: What will print out when the following code runs?
class Animal {
constructor(lg) {
this.legs = lg;
}
}
class Dog extends Animal {
constructor() {
super(4);
}
}
var result = new Dog();
console.log(result.legs);
- 0
- undefined
- null
- 4
Q 4: What will print out when the following code runs?
class Animal {
}
class Cat extends Animal {
constructor() {
super();
this.noise = "meow";
}
}
var result = new Animal();
console.log(result.noise);
- undefined
- null
- “”
- meow
Q 5: What will print out when the following code runs?
class Person {
sayHello() {
console.log("Hello");
}
}
class Friend extends Person {
sayHello() {
console.log("Hey");
}
}
var result = new Friend();
result.sayHello();
- Hello
- Hey
Quiz 3: Knowledge check: Advanced JavaScript Features
Q 1: What will print out when the following code runs?
const meal = ["soup", "steak", "ice cream"]
let [starter] = meal;
console.log(starter);
- soup
- ice cream
- steak
Q 2: The for-of loop works for Object data types.
- true
- false
Q 3: What will print out when the following code runs?
let food = "Chocolate";
console.log(`My favourite food is ${food}`);
- My favourite food is Chocolate
- My favourite food is ${food}
Q 4: What values will be stored in the set collection after the following code runs?
let set = new Set();
set.add(1);
set.add(2);
set.add(3);
set.add(2);
set.add(1);
- 1, 2, 3, 2, 1
- 1, 2, 3
Q 5: What value will be printed out when the following code runs?
let obj = {
key: 1,
value: 4
};
let output = { ...obj };
output.value -= obj.key;
console.log(output.value);
- 1
- 2
- 3
- 4
Q 6: What value will be printed out when the following code runs?
function count(...basket) {
console.log(basket.length)
}
count(10, 9, 8, 7, 6);
- 10, 9, 8, 7, 6
- 1, 2, 3, 4, 5
- 6
- 5
Quiz 4: Knowledge Check – JavaScript in the browser
Q 1: In the following code, the type attribute can be omitted.
<script type="text/javascript">
//Comment
</script>
- true
- false
Q 2: What does the document variable return in JavaScript?
console.log(document);
- The entire body tag of the webpage in the browser’s memory, as a JavaScript object.
- The entire webpage in the browser’s memory, as a JavaScript object.
- The HTML code of the downloaded webpage, as a JavaScript string.
Q 3: What does the following function return?
getElementById('main-heading')
- It doesn’t return anything.
- All elements that have the class attribute with a value main-heading
- The first element that has the id attribute with a value main-heading
- The last element that has the id attribute with a value main-heading
Q 4: After the following code is run, what will happen when the user clicks on a p element in the browser?
document.querySelector('h1').addEventListener('click',
function() {
console.log('clicked');
});
- ‘clicked’ is printed to the console log.
- Nothing.
Q 5: What will be printed when the following code runs?
var result = {
value: 7
};
console.log(JSON.stringify(result));
- {}
- {value: 7}
- {“value”: 7}
Quiz 5: Module quiz: Programming Paradigms
Q 1: Variables declared using ‘let’ can be reassigned.
- true
- false
Q 2: What will print out when the following code runs?
function scopeTest() {
var y = 44;
console.log(x);
}
var x = 33;
scopeTest();
- null
- undefined
- 33
- 44
Q 3: What will print out when the following code runs?
class Cake {
constructor(lyr) {
this.layers = lyr;
}
getLayers() {
return this.layers;
}
}
class WeddingCake extends Cake {
constructor() {
super(2);
}
getLayers() {
return super.getLayers() * 5;
}
}
var result = new WeddingCake();
console.log(result.getLayers());
- 0
- 2
- 5
- 10
Q 4: What will print out when the following code runs?
class Animal {
}
class Dog extends Animal {
constructor() {
this.noise = "bark";
}
makeNoise() {
return this.noise;
}
}
class Wolf extends Dog {
constructor() {
super();
this.noise = "growl";
}
}
var result = new Wolf();
console.log(result.makeNoise());
- bark
- growl
- undefined
Q 5: Consider this code snippet: ‘const [a, b] = [1,2,3,4] ‘. What is the value of b?
- undefined
- 1
- 2
- [1,2,3,4]
Q 6: What value will be printed out when the following code runs?
function count(...food) {
console.log(food.length)
}
count("Burgers", "Fries", null);
- 2
- 3
- “Burgers”, “Fries”, null
- “Burgers”, “Fries”, undefined
Q 7: Which of the following are JavaScript methods for querying the Document Object Model?
- getElementsByClassName
- getElementsById
- getElementById
- getElementByClassName
- queryAllSelectors
- querySelector
Q 8: Which of the following methods convert a JavaScript object to and from a JSON string?
- JSON.parse
- JSON.stringify
- JSON.fromString
- JSON.toString
Q 9: What will be the result of running this code?
const letter = "a"
letter = "b"
- Uncaught TypeError: Assignment to constant variable
- b
- a
- Uncaught SyntaxError: Invalid or unexpected token
Q 10: What is a constructor?
- A function that is called to create an instance of an object.
- An instance of a class.
- A specific object that has been created using the class name.
- An object literal
Programming with JavaScript Week 04 Quiz Answer
Quiz 1: Knowledge check: Introduction to testing
Q 1:What is the correct way to export the timesTwo function as a module so that Jest can use it in testing files?
- export module(timesTwo)
- module(exported(timesTwo))
- document.module.export = timesTwo
- module.exports = timesTwo
Q 2: Testing is a way to verify the expectations you have regarding the behavior of your code.
- true
- false
Q 3: Node.js can be used to build multiple types of applications. Select all that apply.
- Command line applications
- Desktop applications
- Web application backends
Q 4: When the following test executes, what will the test result be?
function add(a, b) {
return a + b;
}
expect(add(10, 5)).toBe(16);
- Success.
- Fail.
Q 5: Which of the following is the slowest and most expensive form of testing?
- Unit testing
- Integration testing
- End-to-end testing (e2e)
Q 6: Mocking allows you to separate the code that you are testing from its related dependencies.
- true
- false
Quiz 2: Module quiz: Testing
Q 1: What is unit testing?
- Unit testing revolves around the idea of having separate, small pieces of code that are easy to test.
- Unit testing tries to imitate how a user might interact with your app.
- Unit testing is testing how parts of your system interact with other parts of our system.
Q 2: When the following test executes, what will the test result be?
function subtract(a, b) {
return a - b;
}
expect(subtract(10, 4)).toBe(6);
- Success.
- Fail.
Q 3: What is End-to-end testing (e2e)?
- End-to-end testing revolves around the idea of having separate, small pieces of code that are easy to test.
- End-to-end testing tries to imitate how a user might interact with your application.
- End-to-end testing is testing how parts of your system interact with other parts of our system.
Q 4: What is Code Coverage?
- A measure of what percentage of your code has failing tests
- A measure of what percentage of your code is covered by tests.
Q 5: Node.js can be used to build web application backends.
- true
- false
Q 6: When the following test executes, what will the test result be?
function multiply(a, b) {
return a;
}
expect(multiply(2, 2)).toBe(4);
- Success.
- Fail.
Q 7: Which command is used to install a Node package?
- package
- pkg
- node
- npm
Q 8: Which file lists all your application’s required node packages?
- node.json
- npm.json
- package.json
- pkg.json
Q 9: A person on your team wants to help with testing. However, they are not a developer and cannot write code. What type of testing is most suited for them?
- Unit testing
- Integration testing
- End-to-end testing
Q 10: What is the recommended way to separate the code that you are testing from its related dependencies?
- Mocking
- module.exports
- End-to-end testing
Programming with JavaScript Week 05 Quiz Answer
Q 1: What will be the output of the following JavaScript?
const a = 10;
const b = 5;
if(a == 7 || b == 5) {
console.log("Green");
} else {
console.log("Blue");
}
- Green
- Blue
Q 2: What will be the output of the following JavaScript?
var x = true;
x = 23;
console.log(x);
- true
- 23
Q 3: What is the data type of the x variable in the following code?
var x = 0 != 1;
- Number
- BigInt
- String
- Boolean
Q 4: What will the following JavaScript code output?
var x = 20;
if(x < 5) {
console.log("Apple");
} else if(x > 10 && x < 20) {
console.log("Pear");
} else {
console.log("Orange");
}
- Apple
- Pear
- Orange
Q 5: What will the following JavaScript code output?
var result = 0;
var i = 4;
while(i > 0) {
result += 2;
i--;
}
console.log(result);
- 0
- 2
- 4
- 8
Q 6: When the following code runs, what will print out?
try {
throw new Error();
console.log('Square');
} catch(err) {
console.log('Circle');
}
- Square
- Circle
Q 7: What’s missing from this JavaScript function declaration?
function(a,b) {
return a + b
}
- The function name.
- The assignment operator.
- The dot notation.
Q 8: What is the output of the code below?
var cat = {}
cat.sound = "meow"
var catSound = "purr"
console.log(cat.sound)
- meow
- purr
- {}
- catSound
Q 9: What is the output of the code below?
var veggies = ['parsley', 'carrot']
console.log(veggies[2])
- undefined
- 2
- 1
- 3
Q 10: Which of the following HTML attributes is used to handle a click event?
- onclick
- addEventListener(‘click’)
- ‘click’
Q 11: How can you add an HTML attribute to an HTML element using JavaScript?
- By invoking the setAttribute method on a given element.
- By invoking the getAttribute method on a given element.
- By invoking the createAttribute method on a given element
Q 12: What does this code do?
function addFive(val) {
return val + 5;
};
module.exports = addFive;
- It defines the addFive function and exports it as a Node module so that it can be used in other files.
- This syntax is invalid.
- It allows you to invoke the addFive function without the parentheses.
Get All Course Quiz Answers of IBM Technical Support Professional Certificate
Introduction to Hardware and Operating Systems Quiz Answers
Introduction to Software, Programming, and Databases Quiz Answers
Introduction to Networking and Storage Quiz Answers
Introduction to Cybersecurity Essentials Quiz Answers
Introduction to Cloud Computing Coursera Quiz Answers
Introduction to Technical Support Coursera Quiz Answers