Question 1

A developer is creating a simple webpage with a button. When a user clicks this button for the first time, a message is displayed.
The developer wrote the JavaScript code below, but something is missing. The message gets displayed time a user clicks the button instead of just the first time.

Which two code lines make this code work as required? Choose 2 answers
  • Question 2

    Refer to the code below:
    Function Person(firstName, lastName, eyecolor) {
    this.firstName =firstName;
    this.lastName = lastName;
    this.eyeColor = eyeColor;
    }
    Person.job = 'Developer';
    const myFather = new Person('John', 'Doe');
    console.log(myFather.job);
    What is the output after the code executes?
  • Question 3

    Refer to the following code:
    <html lang="en">
    <body>
    <div onclick = "console.log('Outer message') ;">
    <button id ="myButton">CLick me<button>
    </div>
    </body>
    <script>
    function displayMessage(ev) {
    ev.stopPropagation();
    console.log('Inner message.');
    }
    const elem = document.getElementById('myButton');
    elem.addEventListener('click' , displayMessage);
    </script>
    </html>
    What will the console show when the button is clicked?
  • Question 4

    A Developer wrote the following code to test a sum3 function that takes in an array of numbers and returns the sum of the first three number in the array, The test passes:
    Let res = sum2([1, 2, 3 ]) ;
    console.assert(res === 6 );
    Res = sum3([ 1, 2, 3, 4]);
    console.assert(res=== 6);
    A different developer made changes to the behavior of sum3 to instead sum all of the numbers present in the array. The test passes:
    Which two results occur when running the test on the updated sum3 function ?
    Choose 2 answers
  • Question 5

    Refer to the code below:

    What is the value of result when Promise. race executes?