Mobile Development and JavaScript | Module 3
Course Name: Mobile Development and JavaScript
Course Link: Mobile Development and JavaScript
These are Mobile Development and JavaScript Week 3 Coursera Answers
Programming Assignment: Building a functional program
// Task 1: Build a function-based console log message generator
function consoleStyler(color, background, fontSize, txt) {
var message = "%c" + txt;
var style = `color: ${color};`;
style += `background: ${background};`;
style += `font-size: ${fontSize};`;
console.log(message, style);
}
// Task 2: Build another console log message generator
function celebrateStyler(reason) {
var fontStyle = "color: tomato; font-size: 50px";
if (reason == "birthday") {
console.log(`%cHappy birthday`, fontStyle);
} else if (reason == "champions") {
console.log(`%cCongrats on the title!`, fontStyle);
} else {
console.log(message, style);
}
}
// Task 3: Run both the consoleStyler and the celebrateStyler functions
consoleStyler('#1d5c63', '#ede6db', '40px', 'Congrats!');
celebrateStyler('birthday');
// Task 4: Insert a congratulatory and custom message
function styleAndCelebrate(color, background, fontSize, txt, reason) {
consoleStyler(color, background, fontSize, txt);
celebrateStyler(reason);
}
// Call styleAndCelebrate
styleAndCelebrate('ef7c8e', 'fae8e0', '30px', 'You made it!', 'champions');
These are Mobile Development and JavaScript Week 3 Coursera Answers
Programming Assignment: Building an object-oriented program
Answer: Please login to see answer.
These are Mobile Development and JavaScript Week 3 Coursera Answers
Programming Assignment: Array and object iteration
Answer: Please login to see answer.
These are Mobile Development and JavaScript Week 3 Coursera Answers
Module 3 Quiz: Programming Paradigms
Q1. Which of the following variable declarations cannot be redeclared but can be reassigned?
- let
- var
- const
- There are no variable declarations which cannot be redeclared but can be reassigned.
Answer: let
Q2. Which of the following variable declarations can be redeclared and reassigned?
- let
- const
- There are no variable declarations which can be redeclared and reassigned.
- var
Answer: var
Q3. What will print out when the following code runs?
function scopeTest() { var y = 44; console.log(x); }
var x = 33;
scopeTest();
- 33
- 44
- undefined
- null
These are Mobile Development and JavaScript Week 3 Coursera Answers
Q4. What will print out when the following code runs?
function scopeTest() { var y = 44; console.log(x); }
scopeTest();
var x = 33;
- 44
- undefined
- 33
- null
Answer: Please login to see answer.
Q5. What is the function of extends in the following code block.
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());
- Replaces the class Cake with the class WeddingCake.
- Creates a child of the class Cake.
- Creates a parent of the class Cake.
- Replaces the class WeddingCake with the class Cake.
Answer: Please login to see answer.
Q6. Which of the following statements describes the outcome of the code block below?
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());
- syntaxError
- console.log(result.makeNoise()) will log undefined
- growl is replaced by bark as the output of console.log(result.makeNoise())
- bark is replaced by growl as the output of console.log(result.makeNoise())
Answer: Please login to see answer.
These are Mobile Development and JavaScript Week 3 Coursera Answers
Q7. What is the function of extends in the following code block.
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());
- Replaces the class Animal with the class Dog.
- Creates a parent of the class Animal.
- Creates a child Dog of the class Animal and a child Wolf of the class Dog.
- Replaces the class Dog with the class Wolf.
Q8. Which of the following snippets would output [3,4] to the console from the snippet:
let a, b, rest;
[a, b, …rest] = [1,2,3,4]
- console.log(c+d)
- console.log(…rest)
- console.log(c,d)
- console.log(rest)
Answer: Please login to see answer.
Q9. What is the value of b in the following code snippet?
const [a, b] = [1,2,3,4]
- 1
- 2
- [1,2,3,4]
- undefined
Answer: Please login to see answer.
These are Mobile Development and JavaScript Week 3 Coursera Answers
Q10. What value will be printed out when the following code runs?
function count(food) { console.log(food.length) }
count(“Burgers”, “Fries”, null);
- 3
- “Burgers”, “Fries”, null
- “Burgers”, “Fries”, undefined
- 7
Answer: Please login to see answer.
Q10. 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”, undefined
- “Burgers”, “Fries”, null
Answer: Please login to see answer.
Q12. Which of the following are JavaScript methods for querying the Document Object Model?
- getElementsByClassName
- getElementsById
- getElementByIds
- getElementByClassName
Answer: Please login to see answer.
These are Mobile Development and JavaScript Week 3 Coursera Answers
Q13. You can access the Document Object Model from what part of your web browser?
- Console tab
- Elements tab
- You cannot access the Document Object Model from your web browser.
- Sources tab
Answer: Please login to see answer.
Q14. JSON.parse is used to do which of the following?
- Convert a JSON string to a JavaScript object.
- Convert a JavaScript object to a JSON number.
- Convert a JavaScript object to a JSON boolean.
- Convert a JavaScript object to a JSON string.
Answer: Please login to see answer.
Q15. What will be the result of running this code?
const letter = “a” letter = “b”;
console.log(letter);
- Uncaught SyntaxError: Invalid or unexpected token
- a
- b
- Uncaught TypeError: Assignment to constant variable
These are Mobile Development and JavaScript Week 3 Coursera Answers
Q16. A function that is called to create an instance of an object is called what?
- Argument
- Method
- An object literal
- Constructor
Answer: Please login to see answer.
These are Mobile Development and JavaScript Week 3 Coursera Answers
Q17. What is the keyword for a constructor function which details how an object will be built?
- Construct
- Extends
- Function
- New
Answer: Please login to see answer.
These are Mobile Development and JavaScript Week 3 Coursera Answers
More Weeks of this course: Click Here
More Coursera Courses: http://progiez.com/coursera