Programming with JavaScript Quiz Answers – Networking Funda

All Weeks Programming with JavaScript Quiz Answers

Programming with JavaScript Week 01 Quiz Answers

Quiz 1: Self review: Declaring variables

Q 1: Did you complete the Declaring variables exercise?

[expand title=View Answer] Yes [/expand]

Q 2: Are you comfortable with using console.log?

[expand title=View Answer] Yes [/expand]

Q 3: Are you comfortable using the assignment operator?

[expand title=View Answer] Yes [/expand]

Quiz: Self Review – Advanced use of operators

Q 1: Did you complete the Advanced use of operators exercise?

[expand title=View Answer] Yes [/expand]

Q 2: Did you find any part of the exercise on the Advanced Use of Operators difficult?

[expand title=View Answer] No [/expand]

Q 3: Would you say that you are able to explain, in your own words, how logical operators &&, ||, and ! work in JavaScript?

[expand title=View Answer] Yes [/expand]

Quiz 3: Knowledge check: Welcome to Programming

Q 1: What is the data type of the value “Hello, World”?

[expand title=View Answer] string [/expand]

Q 2: What is the data type of the value true?

[expand title=View Answer] boolean [/expand]

Q 3: What is the % operator?

[expand title=View Answer] The modulus operator [/expand]

Q 4: What happens when you use the + operator on two strings?

[expand title=View Answer] They get joined into a single string[/expand]

Q 5: What is the operator symbol && represented in JavaScript?

[expand title=View Answer] The logical AND operator [/expand]

Q 6: What happens when you use the + operator on a string and a number?

[expand title=View Answer] They get joined together as if both of them were strings [/expand]

Q 7: What is the value of I after the following code runs?


 var i = 7;
 i += 1;
 i += 2;

[expand title=View Answer] 10 [/expand]

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");
  }

[expand title=View Answer] Hello [/expand]

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");
  }

[expand title=View Answer] Goodbye [/expand]

Q 3: How many times will the following code print the word ‘Hello’?


  for (i = 0; i < 2; i++) {
      console.log("Hello");
  }

[expand title=View Answer]2 [/expand]

Q 4: How many times will the following code print the word ‘Hello’?


  var i = 0;
  while(i < 3) {
    console.log("Hello");
    i++;
  }

[expand title=View Answer] 3 [/expand]

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");
      }​
  }

[expand title=View Answer] 6 [/expand]

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");
  }

[expand title=View Answer] Goodnight [/expand]

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;
  }

[expand title=View Answer] Goodbye [/expand]

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");
  }

[expand title=View Answer] Hello [/expand]

Quiz 8: Module quiz: Introduction to JavaScript

Q 1: You can run JavaScript in a web browser’s dev tools console.

[expand title=View Answer] true[/expand]

Q 2: Which of the following are valid comments in JavaScript? Select all that apply.

[expand title=View Answer] / /Comment 2 [/expand]

Q 3: Which of the following are valid data types in JavaScript? Select all that apply.

[expand title=View Answer]
string

numbers

booleans

null
[/expand]

Q 4: Which of the following is the logical AND operator in JavaScript?

[expand title=View Answer] && [/expand]

Q 5: Which of the following is the assignment operator in JavaScript?

[expand title=View Answer] = [/expand]

Q 6: How many times will the following code print the word ‘Hello’?

[expand title=View Answer] 6 [/expand]


  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");
  }

[expand title=View Answer] Goodbye [/expand]

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");
  }

[expand title=View Answer] Hello [/expand]

Q 9: The result of! false is:

[expand title=View Answer] t​rue [/expand]

Q 10: What does the operator symbol || represent in JavaScript?

[expand title=View Answer] The logical OR operator[/expand]

Programming with JavaScript Week 02 Quiz Answer

Quiz 1: Knowledge check: Arrays, Objects and Functions

Q 1: What data type is the variable item?

[expand title=View Answer] Array [/expand]

  var item = [];

Q 2: What is the value of the result for the following code?

[expand title=View Answer]2[/expand]

  var 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');

[expand title=View Answer] 3 [/expand]

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])

[expand title=View Answer] Ice cream [/expand]

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";

[expand title=View Answer] 4 [/expand]

Q 6: In the following function, the variables a and b are known as _______________.


  function add(a, b) {
      return a + b;
  }

[expand title=View Answer] Parameters [/expand]

Q 7: Which of the following are functions of the Math object?

[expand title=View Answer]
random()

sqrt()
[/expand]

Quiz 2: Knowledge check: Error handling

Q 1: What will be printed when the following code runs?


  var result = null;
  console.log(result);

[expand title=View Answer] null [/expand]

Q 2: When the following code runs, what will print out?


  try {​
    console.log('Hello');
  } catch(err) {​
    console.log('Goodbye');
  }​

[expand title=View Answer] Hello [/expand]

Q 3: If you pass an unsupported data type to a function, what error will be thrown?

[expand title=View Answer] TypeError [/expand]

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");
  }

[expand title=View Answer] undefined[/expand]

Q 5: What will print out when the following code runs?


  throw new Error();
  console.log("Hello");

[expand title=View Answer] Nothing will print out [/expand]

Quiz 3: Module quiz: The Building Blocks of a Program

Q 1: What data type is the variable x?


  var x = {};

[expand title=View Answer] Object [/expand]

Q 2: What will be the output of running the following code?

try {
console.log('hello)
} catch(e) {
console.log('caught')
}

[expand title=View Answer] Caught [/expand]

Q 3: What value is printed when the following code runs?


  var burger = ["bun", "beef", "lettuce", "tomato sauce", "onion", "bun"];
  console.log(burger[2]);

[expand title=View Answer] lettuce[/expand]

Q 4: In the following code, how many methods does the bicycle object have?


  var bicycle = {
      wheels: 2,
      start: function() {

      },
      stop: function() {

      }
  };

[expand title=View Answer] 2 [/expand]

Q 5: When the following code runs, what will print out?


  try {​
    throw new Error();​
    console.log('Hello');
  } catch(err) {​
    console.log('Goodbye');
  }​

[expand title=View Answer] Goodbye[/expand]

Q 6: If you mis-type some code in your JavaScript, what kind of error will that result in?

[expand title=View Answer] TypeError [/expand]

Q 7: Will the following code execute without an error?


  function add(a, b) {
    console.log(a + b)​
  }​

  add(3, "4");​

[expand title=View Answer] Yes [/expand]

Q 8: What will be printed when the following code runs?


  var result;
  console.log(result);

[expand title=View Answer]undefined [/expand]

Q 9: What will be the output of the following code?

var str = "Hello";
str.match("jello");

[expand title=View Answer] null [/expand]

Q 10: What will be the output of the following code?

try {
Number(5).toPrecision(300)
} catch(e) {
console.log("There was an error")
}

[expand title=View Answer] “There was an error” [/expand]

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);

[expand title=View Answer] undefined [/expand]

Q 2: Variables declared using const can be reassigned.

[expand title=View Answer]false [/expand]

Q 3: When a function calls itself, this is known as _____________.

[expand title=View Answer] Recursion [/expand]

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);

[expand title=View Answer] 30[/expand]

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));

[expand title=View Answer] 4 [/expand]

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);

[expand title=View Answer] 2 [/expand]

Q 2: When a class extends another class, this is called ____________.

[expand title=View Answer] Inheritance [/expand]

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);

[expand title=View Answer]4 [/expand]

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);

[expand title=View Answer] undefined [/expand]

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();

[expand title=View Answer] Hey [/expand]

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);

[expand title=View Answer] soup [/expand]

Q 2: The for-of loop works for Object data types.

[expand title=View Answer]false [/expand]

Q 3: What will print out when the following code runs?


    let food = "Chocolate";
    console.log(`My favourite food is ${food}`);

[expand title=View Answer] My favourite food is Chocolate[/expand]

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);

[expand title=View Answer] 1, 2, 3 [/expand]

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);

[expand title=View Answer]3[/expand]

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);

[expand title=View Answer]
10, 9, 8, 7, 6

1, 2, 3, 4, 5

6

5
[/expand]

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>

[expand title=View Answer] true[/expand]

Q 2: What does the document variable return in JavaScript?


    console.log(document);

[expand title=View Answer] The entire webpage in the browser’s memory, as a JavaScript object. [/expand]

.

Q 3: What does the following function return?


    getElementById('main-heading')

[expand title=View Answer] The first element that has the id attribute with a value main-heading[/expand]

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');
        });

[expand title=View Answer] Nothing. [/expand]

Q 5: What will be printed when the following code runs?


    var result = {
      value: 7
    };
    console.log(JSON.stringify(result));

[expand title=View Answer] {“value”: 7} [/expand]

Quiz 5: Module quiz: Programming Paradigms

Q 1: Variables declared using ‘let’ can be reassigned.

[expand title=View Answer] true [/expand]

Q 2: What will print out when the following code runs?


    function scopeTest() {
        var y = 44;

        console.log(x);
    }

    var x = 33;
    scopeTest();

[expand title=View Answer] 33 [/expand]

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());

[expand title=View Answer] 10 [/expand]

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());

[expand title=View Answer] bark [/expand]

Q 5: Consider this code snippet: ‘const [a, b] = [1,2,3,4] ‘. What is the value of b?

[expand title=View Answer] 2 [/expand]

Q 6: What value will be printed out when the following code runs?


    function count(...food) {
        console.log(food.length)
    }

    count("Burgers", "Fries", null);

[expand title=View Answer] 3[/expand]

Q 7: Which of the following are JavaScript methods for querying the Document Object Model?

[expand title=View Answer]
1.getElementsByClassName
2.getElementById
3.querySelector
[/expand]

Q 8: Which of the following methods convert a JavaScript object to and from a JSON string?

[expand title=View Answer]
1.JSON.toString
2.JSON.stringify
[/expand]

Q 9: What will be the result of running this code?

const letter = "a"
letter = "b"

[expand title=View Answer] Uncaught TypeError: Assignment to constant variable  [/expand]

Q 10: What is a constructor?

[expand title=View Answer] A function that is called to create an instance of an object. [/expand]

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?

[expand title=View Answer] module.exports = timesTwo [/expand]

Q 2: Testing is a way to verify the expectations you have regarding the behavior of your code

[expand title=View Answer] true [/expand]

Q 3: Node.js can be used to build multiple types of applications. Select all that apply.

[expand title=View Answer]
Command line applications

Desktop applications

Web application backends
[/expand]

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);

[expand title=View Answer] Fail. [/expand]

Q 5: Which of the following is the slowest and most expensive form of testing?

[expand title=View Answer] End-to-end testing (e2e) [/expand]

Q 6: Mocking allows you to separate the code that you are testing from its related dependencies.

[expand title=View Answer] true [/expand]

Quiz 2: Module quiz: Testing

Q 1: What is unit testing?

[expand title=View Answer] Unit testing revolves around the idea of having separate, small pieces of code that are easy to test. [/expand]

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);

[expand title=View Answer] Success.[/expand]

Q 3: What is End-to-end testing (e2e)?

[expand title=View Answer] End-to-end testing tries to imitate how a user might interact with your application. [/expand]

Q 4: What is Code Coverage?

[expand title=View Answer] A measure of what percentage of your code is covered by tests. [/expand]

.


Q 5: Node.js can be used to build web application backends.

[expand title=View Answer] true [/expand]

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);

[expand title=View Answer] Fail. [/expand]

Q 7: Which command is used to install a Node package?

[expand title=View Answer] npm [/expand]

Q 8: Which file lists all your application’s required node packages?

[expand title=View Answer] package.json [/expand]

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?

[expand title=View Answer] End-to-end testing [/expand]

Q 10: What is the recommended way to separate the code that you are testing from its related dependencies?

[expand title=View Answer] module.exports [/expand]

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");
}

[expand title=View Answer] Green [/expand]

Q 2: What will be the output of the following JavaScript?


var x = true;
x = 23;
console.log(x);

[expand title=View Answer] 23 [/expand]

Q 3: What is the data type of the x variable in the following code?


var x = 0 != 1;

[expand title=View Answer] Number [/expand]

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");
}

[expand title=View Answer]Orange [/expand]

Q 5: What will the following JavaScript code output?


var result = 0;

var i = 4;
while(i > 0) {
    result += 2;
    i--;
}

console.log(result);

[expand title=View Answer] 8 [/expand]

Q 6: When the following code runs, what will print out?


try {
    throw new Error();
    console.log('Square');
} catch(err) {
    console.log('Circle');
}

[expand title=View Answer] Circle [/expand]

Q 7: What’s missing from this JavaScript function declaration?


function(a,b) {
    return a + b
}

[expand title=View Answer] The function name. [/expand]

Q 8: What is the output of the code below?


var cat = {}
cat.sound = "meow"
var catSound = "purr"
console.log(cat.sound)

[expand title=View Answer]meow [/expand]

Q 9: What is the output of the code below?


var veggies = ['parsley', 'carrot']
console.log(veggies[2])

[expand title=View Answer] undefined [/expand]

Q 10: Which of the following HTML attributes is used to handle a click event?

[expand title=View Answer]onclick [/expand]

Q 11: How can you add an HTML attribute to an HTML element using JavaScript?

[expand title=View Answer] By invoking the setAttribute method on a given element. [/expand]

Q 12: What does this code do?


function addFive(val) {
  return val + 5;
};
module.exports = addFive;

[expand title=View Answer] It defines the addFive function and exports it as a Node module so that it can be used in other files. [/expand]

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

Share your love

Newsletter Updates

Enter your email address below and subscribe to our newsletter

Leave a Reply

Your email address will not be published. Required fields are marked *