<< Prev Question Next Question >>

Question 3/50

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

Recent Comments (The most recent comments are at the top.)

Igris - Sep 12, 2025

Line 01: let res = sum3([1, 2, 3]);
Line 02: console.assert(res === 6);
Line 03:
Line 04: res = sum3([1, 2, 3, 4]);
Line 05: console.assert(res === 6);
If sum3 now sums all numbers in the array, which two results occur? (Choose 2)
A) Line 05 fails 
B) Line 02 passes 
C) Line 02 fails 
D) Line 05 passes

Answer: A and B

Explanation :

sum3([1,2,3]) → 6, so Line 02 assertion (res === 6) passes → B.
sum3([1,2,3,4]) → 10, so Line 05 assertion (res === 6) fails → A.

The updated function sums all elements; first case still equals 6, second no longer does.
To fix the test, change Line 05 to console.assert(res === 10);

Ron - Dec 23, 2022

why line 4 assert will fail?
both assers are pointing to same res (with small "r")

Stevan Zivlak - Feb 04, 2022

Line 05 is actually line 04.

Rajesh - Jun 04, 2021

Can I get explanation for the answer please. What is line 05 here?

LEAVE A REPLY

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

Question List (50q)
Question 1: Refer to code below: console.log(0); setTimeout(() =&gt; ( c...
5 commentQuestion 2: A developer uses a parsed JSON string to work with user info...
4 commentQuestion 3: A Developer wrote the following code to test a sum3 function...
Question 4: Refer to HTML below: &lt;p&gt; The current status of an Orde...
3 commentQuestion 5: Why would a developer specify a package.jason as a developed...
Question 6: In the browser, the window object is often used to assign va...
2 commentQuestion 7: developer is trying to convince management that their team w...
2 commentQuestion 8: Which three statements are true about promises ? Choose 3 an...
Question 9: Given the following code: Let x =('15' + 10)*2; What is the ...
Question 10: developer publishes a new version of a package with new feat...
7 commentQuestion 11: Refer to code below: Let first = 'who'; Let second = 'what';...
1 commentQuestion 12: developer has a web server running with Node.js. The command...
2 commentQuestion 13: A developer wrote a fizzbuzz function that when passed in a ...
4 commentQuestion 14: A developer has two ways to write a function: Option A: func...
Question 15: Which javascript methods can be used to serialize an object ...
Question 16: Given two expressions var1 and var2. What are two valid ways...
5 commentQuestion 17: A developer creates a generic function to log custom message...
1 commentQuestion 18: A developer at Universal Containers creates a new landing pa...
2 commentQuestion 19: Refer to the code below? Let searchString = ' look for this ...
Question 20: Which two console logs outputs NaN ? Choose 2 answers...
1 commentQuestion 21: A developer creates an object where its properties should be...
Question 22: Refer to the code below: Let textValue = '1984'; Which code ...
2 commentQuestion 23: Refer to the code below: Async funct on functionUnderTest(is...
Question 24: Considering type coercion, what does the following expressio...
Question 25: A developer creates a class that represents a blog post base...
3 commentQuestion 26: Refer to code below: function Person() { this.firstName = 'J...
Question 27: Refer to the following code: Let obj ={ Foo: 1, Bar: 2 } Let...
2 commentQuestion 28: A developer implements a function that adds a few values. Fu...
Question 29: Refer to code below: Let productSKU = '8675309' ; A develope...
Question 30: Which function should a developer use to repeatedly execute ...
1 commentQuestion 31: A developer is debugging a web server that uses Node.js The ...
Question 32: Refer to the code below: console.log(''start); Promise.resol...
Question 33: A test has a dependency on database.query. During the test t...
Question 34: Consider type coercion, what does the following expression e...
Question 35: Given the JavaScript below: 01 function filterDOM (searchStr...
Question 36: Given the following code: document.body.addEventListener(' c...
1 commentQuestion 37: developer creates a new web server that uses Node.js. It imp...
Question 38: A developer has the function, shown below, that is called wh...
4 commentQuestion 39: What are two unique features of functions defined with a fat...
1 commentQuestion 40: Given the following code: Counter = 0; const logCounter = ()...
1 commentQuestion 41: Refer to the code: (Exhibit) Given the code above, which thr...
2 commentQuestion 42: Given code below: setTimeout (() =&gt; ( console.log(1); ). ...
3 commentQuestion 43: Refer to the following code that performs a basic mathematic...
Question 44: Universal Container(UC) just launched a new landing page, bu...
Question 45: Refer to the following object: const cat ={ firstName: 'Fanc...
4 commentQuestion 46: A developer is leading the creation of a new browser applica...
Question 47: A developer has the following array of student test grades: ...
Question 48: Given the code below: const copy = JSON.stringify([ new Stri...
Question 49: At Universal Containers, every team has its own way of copyi...
2 commentQuestion 50: A developer is asked to fix some bugs reported by users. To ...