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?
Q 2: Are you comfortable with using console.log?
ViewQ 3: Are you comfortable using the assignment operator?
ViewQuiz: Self Review – Advanced use of operators
Q 1: Did you complete the Advanced use of operators exercise?
ViewQ 2: Did you find any part of the exercise on the Advanced Use of Operators difficult?
ViewQ 3: Would you say that you are able to explain, in your own words, how logical operators &&, ||, and ! work in JavaScript?
ViewQuiz 3: Knowledge check: Welcome to Programming
Q 1: What is the data type of the value “Hello, World”?
ViewQ 2: What is the data type of the value true?
ViewQ 3: What is the % operator?
ViewQ 4: What happens when you use the + operator on two strings?
ViewQ 5: What is the operator symbol && represented in JavaScript?
ViewQ 6: What happens when you use the + operator on a string and a number?
ViewQ 7: What is the value of I after the following code runs?
var i = 7;
i += 1;
i += 2;
ViewQuiz 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");
}
ViewQ 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");
}
ViewQ 3: How many times will the following code print the word ‘Hello’?
for (i = 0; i < 2; i++) {
console.log("Hello");
}
ViewQ 4: How many times will the following code print the word ‘Hello’?
var i = 0;
while(i < 3) {
console.log("Hello");
i++;
}
ViewQ 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");
}
}
ViewQ 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");
}
ViewQ 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;
}
ViewQ 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");
}
ViewQuiz 8: Module quiz: Introduction to JavaScript
Q 1: You can run JavaScript in a web browser’s dev tools console.
ViewQ 2: Which of the following are valid comments in JavaScript? Select all that apply.
ViewQ 3: Which of the following are valid data types in JavaScript? Select all that apply.
Viewnumbers
booleans
null
Q 4: Which of the following is the logical AND operator in JavaScript?
ViewQ 5: Which of the following is the assignment operator in JavaScript?
ViewQ 6: How many times will the following code print the word ‘Hello’?
View
for(var i = 0; i <= 5; i++) {
console.log("Hello");
}
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");
}
ViewQ 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");
}
ViewQ 9: The result of! false is:
ViewQ 10: What does the operator symbol || represent in JavaScript?
ViewProgramming with JavaScript Week 02 Quiz Answer
Quiz 1: Knowledge check: Arrays, Objects and Functions
Q 1: What data type is the variable item?
Viewvar item = [];
Q 2: What is the value of the result for the following code?
Viewvar result = “Hello”.indexOf(‘l’);
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');
ViewQ 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])
ViewQ 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";
ViewQ 6: In the following function, the variables a and b are known as _______________.
function add(a, b) {
return a + b;
}
ViewQ 7: Which of the following are functions of the Math object?
Viewsqrt()
Quiz 2: Knowledge check: Error handling
Q 1: What will be printed when the following code runs?
var result = null;
console.log(result);
ViewQ 2: When the following code runs, what will print out?
try {
console.log('Hello');
} catch(err) {
console.log('Goodbye');
}
ViewQ 3: If you pass an unsupported data type to a function, what error will be thrown?
ViewQ 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");
}
ViewQ 5: What will print out when the following code runs?
throw new Error();
console.log("Hello");
ViewQuiz 3: Module quiz: The Building Blocks of a Program
Q 1: What data type is the variable x?
var x = {};
ViewQ 2: What will be the output of running the following code?
try {
console.log('hello)
} catch(e) {
console.log('caught')
}
ViewQ 3: What value is printed when the following code runs?
var burger = ["bun", "beef", "lettuce", "tomato sauce", "onion", "bun"];
console.log(burger[2]);
ViewQ 4: In the following code, how many methods does the bicycle object have?
var bicycle = {
wheels: 2,
start: function() {
},
stop: function() {
}
};
ViewQ 5: When the following code runs, what will print out?
try {
throw new Error();
console.log('Hello');
} catch(err) {
console.log('Goodbye');
}
ViewQ 6: If you mis-type some code in your JavaScript, what kind of error will that result in?
ViewQ 7: Will the following code execute without an error?
function add(a, b) {
console.log(a + b)
}
add(3, "4");
ViewQ 8: What will be printed when the following code runs?
var result;
console.log(result);
ViewQ 9: What will be the output of the following code?
var str = "Hello";
str.match("jello");
ViewQ 10: What will be the output of the following code?
try {
Number(5).toPrecision(300)
} catch(e) {
console.log("There was an error")
}
ViewProgramming 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);
ViewQ 2: Variables declared using const can be reassigned.
ViewQ 3: When a function calls itself, this is known as _____________.
ViewQ 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);
ViewQ 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));
ViewQuiz 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);
ViewQ 2: When a class extends another class, this is called ____________.
ViewQ 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);
ViewQ 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);
ViewQ 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();
ViewQuiz 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);
ViewQ 2: The for-of loop works for Object data types.
ViewQ 3: What will print out when the following code runs?
let food = "Chocolate";
console.log(`My favourite food is ${food}`);
ViewQ 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);
ViewQ 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);
ViewQ 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);
View1, 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>
ViewQ 2: What does the document variable return in JavaScript?
console.log(document);
View.
Q 3: What does the following function return?
getElementById('main-heading')
ViewQ 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');
});
ViewQ 5: What will be printed when the following code runs?
var result = {
value: 7
};
console.log(JSON.stringify(result));
ViewQuiz 5: Module quiz: Programming Paradigms
Q 1: Variables declared using ‘let’ can be reassigned.
ViewQ 2: What will print out when the following code runs?
function scopeTest() {
var y = 44;
console.log(x);
}
var x = 33;
scopeTest();
ViewQ 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());
ViewQ 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());
ViewQ 5: Consider this code snippet: ‘const [a, b] = [1,2,3,4] ‘. What is the value of b?
ViewQ 6: What value will be printed out when the following code runs?
function count(...food) {
console.log(food.length)
}
count("Burgers", "Fries", null);
ViewQ 7: Which of the following are JavaScript methods for querying the Document Object Model?
View2.getElementById
3.querySelector
Q 8: Which of the following methods convert a JavaScript object to and from a JSON string?
View2.JSON.stringify
Q 9: What will be the result of running this code?
const letter = "a"
letter = "b"
ViewQ 10: What is a constructor?
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?
Q 2: Testing is a way to verify the expectations you have regarding the behavior of your code
ViewQ 3: Node.js can be used to build multiple types of applications. Select all that apply.
ViewDesktop 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);
ViewQ 5: Which of the following is the slowest and most expensive form of testing?
ViewQ 6: Mocking allows you to separate the code that you are testing from its related dependencies.
ViewQuiz 2: Module quiz: Testing
Q 1: What is unit testing?
ViewQ 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);
ViewQ 3: What is End-to-end testing (e2e)?
ViewQ 4: What is Code Coverage?
View.
Q 5: Node.js can be used to build web application backends.
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);
ViewQ 7: Which command is used to install a Node package?
ViewQ 8: Which file lists all your application’s required node packages?
ViewQ 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?
ViewQ 10: What is the recommended way to separate the code that you are testing from its related dependencies?
ViewProgramming 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");
}
ViewQ 2: What will be the output of the following JavaScript?
var x = true;
x = 23;
console.log(x);
ViewQ 3: What is the data type of the x variable in the following code?
var x = 0 != 1;
ViewQ 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");
}
ViewQ 5: What will the following JavaScript code output?
var result = 0;
var i = 4;
while(i > 0) {
result += 2;
i--;
}
console.log(result);
ViewQ 6: When the following code runs, what will print out?
try {
throw new Error();
console.log('Square');
} catch(err) {
console.log('Circle');
}
ViewQ 7: What’s missing from this JavaScript function declaration?
function(a,b) {
return a + b
}
ViewQ 8: What is the output of the code below?
var cat = {}
cat.sound = "meow"
var catSound = "purr"
console.log(cat.sound)
ViewQ 9: What is the output of the code below?
var veggies = ['parsley', 'carrot']
console.log(veggies[2])
ViewQ 10: Which of the following HTML attributes is used to handle a click event?
View‘
Q 11: How can you add an HTML attribute to an HTML element using JavaScript?
ViewQ 12: What does this code do?
function addFive(val) {
return val + 5;
};
module.exports = addFive;
ViewGet 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