Programming with JavaScript Coursera Quiz Answers
In this article i am gone to share Coursera Course: Programming with JavaScript by Meta | Programming with JavaScript Coursera Quiz Answers with you..
Enroll Link: Introduction to Front-End Development
Programming with JavaScript Coursera Quiz Answers
Week 1 Quiz Answers
Knowledge check: Welcome to Programming Quiz Answer
Question 1)
What is the data type of the value “Hello, World”?
- string
- number
- boolean
Question 2)
What is the data type of the value true ?
- string
- number
- boolean
Question 3)
What is the % operator?
- The modulus operator
- The division operator
- The concatenation operator
Question 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
Question 5)
What is the operator symbol && represent in JavaScript?
- The logical OR operator
- The logical AND operator
- The logical NOT operator
Question 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
Question 7)
What is the value of i after the following code runs?
var i = 7; i += 1; i += 2;
- 7
- 8
- 9
- 10
Knowledge check – Conditionals and loops Quiz Answer
Question 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
Question 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
Question 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
Question 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
Question 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
Question 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
Question 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");
- Hello
- Goodnight
- Goodbye
Question 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
Visit This Link: Module quiz: Introduction to JavaScript Quiz Answers
Week 2 Quiz Answers
Knowledge check: Arrays, Objects and Functions Quiz Answer
Question 1)
What data type is the variable item ?
var item = [];
- Boolean
- Function
- Array
Question 2)
What is the value of result for the following code?
var result = "Hello".indexOf('l');
- 1
- 2
- 3
- 4
Question 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
Question 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
Question 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
Question 6)
In the following function, the variables a and b are known as _______________.
function add(a, b) { return a + b; }
- Parameters
- Return Values
Question 7)
Which of the following are functions of the Math object?
- random()
- round()
- sqrt()
- trim()
Knowledge check: Error handling Quiz Answer
Question 1)
What will be printed when the following code runs?
var result = null; console.log(result);
- undefined
- null
- 0
Question 2)
When the following code runs, what will print out?
try { console.log('Hello'); } catch(err) { console.log('Goodbye'); }
- Hello
- Goodbye
Question 3)
If you pass an unsupported data type to a function, what error will be thrown?
- RangeError
- SyntaxErrror
- TypeError
Question 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
Question 5)
What will print out when the following code runs?
throw new Error(); console.log("Hello");
- Hello
- Nothing will print out.
Visit This Link: Module quiz: The Building Blocks of a Program Quiz Answers
Week 3 Quiz Answers
Knowledge check: Introduction to Functional Programming Quiz Answer
Question 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
Question 2)
Variables declared using const can be reassigned.
- true
- false
Question 3)
When a function calls itself, this is known as _____________.
- Recursion
- Looping
- Higher-order Function
Question 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);
- 10
- 20
- 30
- 40
Question 5)
What value will print out when the following code runs?
function two() { return 2; } function one() { return 1; } function calculate(initialValue, incrementValue) {
- 1
- 2
- 3
- 4
Knowledge check: Introduction to Object-Oriented Programming Quiz Answer
Question 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
Question 2)
When a class extends another class, this is called ____________.
- Inheritance
- Extension
Question 3)
What will print out when the following code runs?
class Animal { constructor(lg) { this.legs = lg; } } class Dog extends Animal { constructor() { super(4);
- 0
- undefined
- null
- 4
Question 4)
What will print out when the following code runs?
class Animal {} class Cat extends Animal { constructor() { super(); this.noise = "meow"; }
- undefined
- null
- “”
- meow
Question 5)
What will print out when the following code runs?
class Person { sayHello() { console.log("Hello"); } } class Friend extends Person { sayHello() { console.log("Hey");
- Hello
- Hey
Knowledge check: Advanced JavaScript Features Quiz Answer
Question 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
Question 2)
The for-of loop works for Object data types.
- true
- false
Question 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}
Question 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
Question 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
Question 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
Knowledge Check – JavaScript in the browser Quiz Answer
Question 1)
In the following code, the type attribute can be omitted.
<script type="text/javascript"> //Comment </script>
- true
- false
Question 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.
Question 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
Question 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.
Question 5)
What will be printed when the following code runs?
var result = { value: 7 }; console.log(JSON.stringify(result));
- {}
- {value: 7}
- {“value”: 7}
Week 3 Programming Assignment
Visit This Link: Module quiz: Programming Paradigms Quiz Answers
Week 4 Quiz Answers
Knowledge check: Introduction to testing Quiz Answer
Question 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
Question 2)
Testing is a way to verify the expectations you have regarding the behavior of your code.
- true
- false
Question 3)
Node.js can be used to build multiple types of applications. Select all that apply.
- Command line applications
- Desktop applications
- Web application backends
Question 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.
Question 5)
Which of the following is the slowest and most expensive form of testing?
- Unit testing
- Integration testing
- End-to-end testing (e2e)
Question 6)
Mocking allows you to separate the code that you are testing from its related dependencies.
- true
- false
Week 4 Programming Assignment
Visit This Link: Module quiz: Testing Quiz Answers
Week 5 Quiz Answers
Week 5 Programming Assignment
Visit This Link: Final graded quiz: Programming with JavaScript Quiz Answers