Mobile Development and JavaScript | Module 5

Course Name: Mobile Development and JavaScript

Course Link: Mobile Development and JavaScript

These are Mobile Development and JavaScript Week 5 Coursera Answers


Programming Assignment: Little Lemon Receipt Maker

// Given variables
const dishData = [
    {
        name: "Italian pasta",
        price: 9.55
    },
    {
        name: "Rice with veggies",
        price: 8.65
    },
    {
        name: "Chicken with potatoes",
        price: 15.55
    },
    {
        name: "Vegetarian Pizza",
        price: 6.45
    },
];
const tax = 1.20;

// Implement getPrices()
function getPrices(taxBoolean) {
    for (let i = 0; i < dishData.length; i++) {
        let finalPrice;
        if (taxBoolean === true) {
            finalPrice = dishData[i].price * tax;
        } else if (taxBoolean === false) {
            finalPrice = dishData[i].price;
        } else {
            console.log("You need to pass a boolean to the getPrices call!");
            return;
        }
        console.log("Dish: " + dishData[i].name + " Price: $" + finalPrice);
    }
}

// Implement getDiscount()
function getDiscount(taxBoolean, guests) {
    getPrices(taxBoolean);
    if (typeof guests === 'number' && guests > 0 && guests < 30) {
        let discount = 0;
        if (guests < 5) {
            discount = 5;
        } else if (guests >= 5) {
            discount = 10;
        }
        console.log('Discount is: $' + discount);
    } else {
        console.log('The second argument must be a number between 0 and 30');
    }
}

// Call getDiscount()
getDiscount(true, 3);
getDiscount(true, 7);
getDiscount(false, 10);
getDiscount(true, -5);

These are Mobile Development and JavaScript Week 5 Coursera Answers


Module 5 Quiz: Final Graded Quiz: Programming with JavaScript

Q1. 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"); 
}
  • Nothing
  • Blue
  • syntaxError
  • Green

Answer: Green


Q2. What will be the output of the following JavaScript?

var message = "Hello"; 
message += " World!"; 
message = "Goodbye!"; 
console.log(message);
  • Goodbye!
  • World!
  • Hello
  • Hello World!

Answer: Goodbye!


Q3. What will be the output of the following JavaScript?

var x = true;
x = 23; 
console.log(x);
  • undefined
  • true
  • rangeError
  • 23
Answer: 23

These are Mobile Development and JavaScript Week 5 Coursera Answers


Q4. What is the data type of the x variable in the following code?
var x = “Hello”;

  • BigInt
  • Number
  • String
  • Boolean
Answer: String

Q5. What is the data type of the x variable in the following code?
var x = 0 != 1;

  • String
  • BigInt
  • Number
  • Boolean
Answer: Boolean

Q6. What is the data type of the x variable in the following code?
var x = 23.2;

  • Boolean
  • Number
  • String
  • BigInt
Answer: Number

These are Mobile Development and JavaScript Week 5 Coursera Answers


Q7. What will the following JavaScript code output?

var x = 20; 
if(x >= 10) {
    console.log("Apple"); 
    } 
else if(x <= 5) {
    console.log("Pear"); 
    } 
else { console.log("Orange"); }
  • undefined
  • Orange
  • Apple
  • Pear
Answer: Apple

Q8. What will the following JavaScript code output?

var x = 10; 
if(x > 10) {
     console.log("Apple"); 
     } 
else if(x > 5) { 
     console.log("Pear"); 
     } 
else {
     console.log("Orange");  
     }
  • Pear
  • Orange
  • undefined
  • Apple
Answer: Pear

Q9. What will the following JavaScript code output?

var result = 0; 
var i = 0; 
var limit = 3; 
while(i < limit) {
    result += 2; i++; 
} 
console.log(result);
  • 2
  • 6
  • 3
  • 0
Answer: 6

These are Mobile Development and JavaScript Week 5 Coursera Answers


Q10. What will the following JavaScript code output?

var result = 0; 
var i = 4; 
while(i > 0) {
    result += 2; i--; 
} 
console.log(result);
  • 8
  • 4
  • 2
  • 0
Answer: 8

Q11. When the following code runs, what will print out?
try { throw new Error(); console.log(‘Square’); }
catch(err) { console.log(‘Circle’); }

  • Circle
  • undefined
  • sytaxError
  • Square
Answer: Circle

Q12. What will the following JavaScript code output?
console.log(result);
var result = 7;

  • 7
  • null
  • undefined
  • result()
Answer: undefined

These are Mobile Development and JavaScript Week 5 Coursera Answers


Q13. What’s missing from this JavaScript function declaration?
function(a,b) 
{ return a + b } 

  • The function name.
  • The assignment operator.
  • The dot notation.
  • The bracket notation.
Answer: The function name.

Q14. In the following JavaScript code snippet, what is missing for the code to return the value 15?
function addTwo(a,b) { return a }
addTwo(5,10)

  • Attribute
  • Bracket notation
  • +b in the return statement.
Answer: +b in the return statement.

Q15. What is the output of the code below?

var cat = {} 
cat["sound"] = "meow"; 
var catSound = "purr";
console.log(cat.sound)
  • catSound
  • meow
  • {}
  • purr
Answer: meow

These are Mobile Development and JavaScript Week 5 Coursera Answers


Q16. What is the output of the code below?

var cat = {} 
cat.sound = "meow"; 
var catSound = "purr" 
console.log(catSound)
  • {}
  • purr
  • catSound
  • meow
Answer: meow

Q17. True or False: The pop method will remove the last item in an array.

  • True
  • False
Answer: True

Q18. True or False: The second argument passed to the addEventListener function is the function that handles the event when triggered.

  • False
  • True
Answer: True

These are Mobile Development and JavaScript Week 5 Coursera Answers

See also  Mobile Development and JavaScript | Module 1

Q19. What is the first argument passed to the addEventListener function?

  • A string describing the type of event (such as, ‘click’).
  • A function that will handle the event.
  • The name of the method.
  • The target of the event.
Answer: A string describing the type of event (such as, ‘click’).

Q20. How do you create a new h2 element using JavaScript?

  • With document.addElement(‘h2’)
  • With document.createElement(‘h2’)
  • With document.buildElement(‘h2’)
Answer: With document.createElement('h2')

Q21. What does this line of code do?
document.createElement(‘h2’).innerText = “Heading Level 2”

  • It adds an inner-text HTML attribute to the h2 element.
  • This syntax is invalid.
  • It adds “Heading level 2” to the innerText class.
  • It creates an h2 element without adding it to the page.
Answer: It creates an h2 element without adding it to the page.

These are Mobile Development and JavaScript Week 5 Coursera Answers


Q22. 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.
  • It allows you to invoke the addFive function without the parentheses.
  • This syntax is invalid.
  • It allows you to invoke the addFive function without writing unnecessary code.
Answer: It defines the addFive function and exports it as a Node module so that it can be used in other files.

Q23. What part of the following code should be changed for the code to run correctly.
const addFive = require(‘./addFive.js’)

  • .js should be replaced with .node.
  • addFive should be a function.
  • (‘./addFive.js’) should be in brackets.
  • .js is unnecessary after addFive.
Answer: .js is unnecessary after addFive.

Q24. DevTools console is frequently used to perform what function?

  • Testing your code.
  • Installing npm.
  • Downloading packages.
  • Running Javascript in a web browser.
Answer: Running Javascript in a web browser.

These are Mobile Development and JavaScript Week 5 Coursera Answers


Q25. What web browser tool can you use to run Javascript?

  • GUI
  • console.log
  • Package manager
  • DevTools Console
Answer: DevTools Console

Q26. /* Comment */ is used to indicate which of the following information types in Javascript?

  • unfinished code
  • multi-line comments
  • inline comments
  • test code
Answer: multi-line comments

Q27. Which of the following comments is the correct syntax for an inline comment?

  • // Comment 2
  • \ Comment 1
  • ## ## Comment 3 ##
  • /* * Comment 4 */
Answer: // Comment 2, /* * Comment 4 */

These are Mobile Development and JavaScript Week 5 Coursera Answers


Q28. Which of the following selections is not a data type?

  • booleans
  • numbers
  • function
  • string
Answer: function

Q29. Which data type is used to store a true or false value?

  • function
  • numbers
  • booleans
  • string
Answer: booleans

Q30. Which data type is used to store the value “Welcome to Javascript!”?

  • numbers
  • booleans
  • function
  • string
Answer: string

These are Mobile Development and JavaScript Week 5 Coursera Answers


Q31. Which statement describes the difference between == and ===?

  • == is used for numbers and === is used for strings.
  • == operator compares the values as well as the data types of the operands.
  • === operator compares the values as well as the data types of the operands and == symbol is used to assign variables.
  • There is no difference between == and ===.
Answer: === operator compares the values as well as the data types of the operands and == symbol is used to assign variables.

Q32. What is unit testing?

  • Unit testing gives you an efficiency rating for your code measured in units.
  • Unit testing tries to imitate how a user might interact with your app.
  • Unit testing revolves around the idea of having separate, small pieces of code that are easy to test.
  • Unit testing is testing how parts of your system interact with other parts of our system.
Answer: Unit testing revolves around the idea of having separate, small pieces of code that are easy to test.

Q33. Having separate, small pieces of code that are easy to test describes what type of testing?

  • Unit testing
  • Integration testing
  • End-to-end testing
  • Post-hoc testing
Answer: Unit testing

These are Mobile Development and JavaScript Week 5 Coursera Answers

See also  Mobile Development and JavaScript | Module 3

Q34. True or False: End-to-end testing is the fastest and least expensive type of testing.

  • False
  • True.
Answer: False

Q35. Which statement best describes 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 is a comprehensive test that starts at the beginning of your code and runs to the end.
  • 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.
Answer: End-to-end testing tries to imitate how a user might interact with your application.

Q36. True or False: You can install packages from the npm repository using the node command.

  • True
  • False
Answer: False

These are Mobile Development and JavaScript Week 5 Coursera Answers


Q37. Which statement best describes the function of package.json?

  • Turn your code into an application.
  • Download npm packages.
  • Store all the dependencies required for application.
  • Store all the testing code.
Answer: Store all the dependencies required for application.

Q38. True or False: If you build a project with multiple node packages, they will all be listed inside the package.json file.

  • True
  • False
Answer: False

Q39. Which feature is used to mock data in Javascript?

  • Jest Snapshot
  • Jest Fakes
  • Jest Mock functions
  • External mock libraries
Answer: Jest Mock functions

These are Mobile Development and JavaScript Week 5 Coursera Answers


Q40. Which statement does not describe the process of mocking?

  • You can test the front end functionality of your web app by mocking the data as if it came back from a server.
  • Mocking is a substitute for testing.
  • Mocks allow you to pretend that users are already there if the backend hasn’t been built yet.
  • Mocking allows you to separate the code that you are testing from its related dependencies.
Answer: You can test the front end functionality of your web app by mocking the data as if it came back from a server.

Q41. True or False: End-to-end tests can be performed in a web browser without writing code.

  • False
  • True
Answer: True

Q42. Which of the following variable declarations cannot be redeclared or reassigned?

  • There are no variable declarations which cannot be reassigned.
  • const
  • var
  • let
Answer: const

These are Mobile Development and JavaScript Week 5 Coursera Answers


Q43. Which of the following variable declarations cannot be redeclared but can be reassigned?

  • let
  • const
  • There are no variable declarations which cannot be redeclared but can be reassigned.
  • var
Answer: let

Q44. What will print out when the following code runs?

class Game {
    constructor(score) {this.score = points; } 
    getPoints() { return this.score; }
}
class Bonus extends Game {
    constructor() { super(2);} 
    getpoints() { return super.getPoints() * 5; } 
} 
var result = new Bonus(); 
console.log(result.getPoints()); 
  • 2
  • 0
  • 10
  • 5
Answer: 10

Q45. What is the function of extends in the following code block.

class Animal { } 
class Cat extends Animal { 
    constructor() { this.noise = "meow"; } 
    makeNoise() { return this.noise; } 
} 
class Tiger extends Cat { 
    constructor() { super(); this.noise = "growl"; } 
} 
var result = new Tiger(); 
console.log(result.makeNoise());
  • Creates a parent of the class Animal.
  • Replaces the class Animal with the class Cat.
  • Replaces the class Cat with the class Tiger.
  • Creates a child Cat of the class Animal and a child Tiger of the class Cat.
Answer: Creates a child Cat of the class Animal and a child Tiger of the class Cat.

These are Mobile Development and JavaScript Week 5 Coursera Answers

See also  Mobile Development and JavaScript | Module 4

Q46. What will print out when the following code runs?

class Animal { } 
class Cat extends Animal { 
    constructor() { this.noise = "meow"; } 
    makeNoise() { return this.noise; } 
} 
class Tiger extends Cat { 
    constructor() { super(); this.noise = "growl"; } 
} 
var result = new Tiger(); 
console.log(result.makeNoise());
  • syntaxError
  • growl
  • undefined
  • meow
Answer: growl

Q47. console.log(…rest) will output which of the following for the below statement?
const [a, b, …rest] = [1,2,3,4]

  • undefined
  • 1
  • [3,4]
  • 2
Answer: [3,4]

Q48. Which statement will log [3,4] to the console from the following code snippet?
let a, b, rest;
[a, b, …rest] = [1,2,3,4]

  • console.log(…rest)
  • console.log(rest)
  • console.log(c+d)
  • console.log(c,d)
Answer: console.log(rest)

These are Mobile Development and JavaScript Week 5 Coursera Answers


Q49. True or false: The rest parameter syntax allows a function to accept an indefinite number of arguments as an array.

  • True
  • False
Answer: True

Q50. What value will be printed out when the following code runs?

function count(...food) 
{ console.log(food.length) } 
count("Burgers", "Fries", null);
  • “Burgers”, “Fries”, null
  • 2
  • 3
  • “Burgers”, “Fries”, undefined
Answer: 3

Q51. JSON.parse is a static method used to do which of the following?

  • Convert a JavaScript object to a JSON string.
  • Convert a JSON string to a JavaScript object.
  • Convert a JavaScript object to a JSON number.
  • Convert a JavaScript object to a JSON boolean.
Answer: Convert a JavaScript object to a JSON string., Convert a JSON string to a JavaScript object.

These are Mobile Development and JavaScript Week 5 Coursera Answers


Q52. Which of the following static methods convert a JSON string into an object?

  • JSON.parse
  • JSON.stringify
  • JSON.fromString
  • JSON.toString
Answer: JSON.parse

Q53. A function that is called to create an instance of an object is called what?

  • Constructor
  • Method
  • An object literal
  • Argument
Answer: Constructor

These are Mobile Development and JavaScript Week 5 Coursera Answers


Q54. What keyword, used with a constructor function, details how an object will be built?

  • Extends
  • New
  • Construct
  • Function
Answer: New

These are Mobile Development and JavaScript Week 5 Coursera Answers


Q55. The Object Oriented Programming paradigm can best be described how?

  • It works by writing efficient code.
  • It works by keeping data in meaningful objects but keeps functionality separate.
  • It works by keeping the data and functionality grouped in meaningful objects.
  • It works by keeping the data and functionality separate.
Answer: It works by keeping the data and functionality grouped in meaningful objects.

These are Mobile Development and JavaScript Week 5 Coursera Answers


Q56. Which of the following concepts are not associated with the concept of functional programming?

  • Higher-order function
  • First-class functions
  • Pure functions and side-effects
  • Objects
Answer: Objects

These are Mobile Development and JavaScript Week 5 Coursera Answers


Q57. The Functional Programming paradigm can best be described how?

  • It works by writing efficient code.
  • It works by keeping the data and functionality separate.
  • It works by keeping data in meaningful objects but keeps functionality separate.
  • It works by keeping the data and functionality grouped in meaningful objects.
Answer: It works by keeping the data and functionality separate.

These are Mobile Development and JavaScript Week 5 Coursera Answers


More Weeks of this course: Click Here

More Coursera Courses: http://progiez.com/coursera


Mobile Development and JavaScript Week 5 Coursera