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?

View
Yes

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

View
Yes

Q 3: Are you comfortable using the assignment operator?

View
Yes

Quiz: Self Review – Advanced use of operators

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

View
Yes

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

View
No

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

View
Yes

Quiz 3: Knowledge check: Welcome to Programming

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

View
string

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

View
boolean

Q 3: What is the % operator?

View
The modulus operator

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

View
They get joined into a single string

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

View
The logical AND operator

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

View
They get joined together as if both of them were strings

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


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

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

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

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


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

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


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

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

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

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

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

Quiz 8: Module quiz: Introduction to JavaScript

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

View
true

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

View
/ /Comment 2

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

View
string

numbers

booleans

null

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

View
&&

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

View
=

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

View
6

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

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

Q 9: The result of! false is:

View
t​rue

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

View
The logical OR operator

Programming with JavaScript Week 02 Quiz Answer

Quiz 1: Knowledge check: Arrays, Objects and Functions

Q 1: What data type is the variable item?

View
Array

  var item = [];

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

View
2

  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');
View
3

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])
View
Ice cream

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

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


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

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

View
random()

sqrt()

Quiz 2: Knowledge check: Error handling

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


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

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


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

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

View
TypeError

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

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


  throw new Error();
  console.log("Hello");
View
Nothing will print out

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

Q 1: What data type is the variable x?


  var x = {};
View
Object

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

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

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


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

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


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

      },
      stop: function() {

      }
  };
View
2

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


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

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

View
TypeError

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


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

  add(3, "4");​
View
Yes

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


  var result;
  console.log(result);
View
undefined

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

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

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

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

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

Q 2: Variables declared using const can be reassigned.

View
false

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

View
Recursion

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

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

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

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

View
Inheritance

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

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

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

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

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

View
false

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


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

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);
View
1, 2, 3

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

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);
View
10, 9, 8, 7, 6

1, 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>

View
true

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


    console.log(document);
View
The entire webpage in the browser’s memory, as a JavaScript object.

.

Q 3: What does the following function return?


    getElementById('main-heading')
View
The first element that has the id attribute with a value main-heading

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

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


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

Quiz 5: Module quiz: Programming Paradigms

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

View
true

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


    function scopeTest() {
        var y = 44;

        console.log(x);
    }

    var x = 33;
    scopeTest();
View
33

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

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

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

View
2

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


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

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

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

View
1.getElementsByClassName
2.getElementById
3.querySelector

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

View
1.JSON.toString
2.JSON.stringify

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

const letter = "a"
letter = "b"
View
Uncaught TypeError: Assignment to constant variable 

Q 10: What is a constructor?

View
A function that is called to create an instance of an object.

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?

View
module.exports = timesTwo

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

View
true

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

View
Command line applications

Desktop 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);
View
Fail.

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

View
End-to-end testing (e2e)

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

View
true

Quiz 2: Module quiz: Testing

Q 1: What is unit testing?

View
Unit testing revolves around the idea of having separate, small pieces of code that are easy to test.

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);
View
Success.

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

View
End-to-end testing tries to imitate how a user might interact with your application.

Q 4: What is Code Coverage?

View
A measure of what percentage of your code is covered by tests.

.


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

View
true

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);
View
Fail.

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

View
npm

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

View
package.json

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?

View
End-to-end testing

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

View
module.exports

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

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


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

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


var x = 0 != 1;
View
Number

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

Q 5: What will the following JavaScript code output?


var result = 0;

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

console.log(result);
View
8

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


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

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


function(a,b) {
    return a + b
}
View
The function name.

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


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

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


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

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

View
onclick

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

View
By invoking the setAttribute method on a given element.

Q 12: What does this code do?


function addFive(val) {
  return val + 5;
};
module.exports = addFive;
View
It defines the addFive function and exports it as a Node module so that it can be used in other files.

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

Team Networking Funda
Team Networking Funda

We are Team Networking Funda, a group of passionate authors and networking enthusiasts committed to sharing our expertise and experiences in networking and team building. With backgrounds in Data Science, Information Technology, Health, and Business Marketing, we bring diverse perspectives and insights to help you navigate the challenges and opportunities of professional networking and teamwork.

Leave a Reply

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