Final graded quiz: Programming with JavaScript

Final graded quiz: Programming with JavaScript

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

     const a = true;
     if(!a) {
         console.log("Green");
     } else {
         console.log("Blue");
     }
    
    • Green

    • Blue

    • Nothing

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

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

    • 23

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

     var x = 23.2;
    
    • Number

    • BigInt

    • String

    • Boolean

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

    • Pear

    • Orange

  5. 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);
    
    • 0

    • 2

    • 3

    • 6

  6. What will the following JavaScript code output?

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

    • undefined

    • 7

  7. What's missing from this JavaScript function declaration?

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

    • The assignment operator.

    • The dot notation.

  8. What is the output of the code below?

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

    • purr

    • {}

    • catSound

  9. What is the output of the code below?

     var veggies = []
     veggies.push('parsley')
     veggies.push('carrot')
     console.log(veggies[2])
    
    • undefined

    • 2

    • 1

    • 3

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

    • onclick

    • addEventListener('click')

    • 'click'

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

    • With document.createElement('h2')

    • With document.buildElement('h2')

    • With document.addElement('h2')

  12. Is the code below missing a .js after the ./addFive ?

    const addFive = require('./addFive')
    
    • true

    • false