Ask coding questions

← Back to all posts
Why does this problem expect one of the answers to be 16?
BritnyLain (1)

Write a function called productOfValues which takes in an object of key/value pairs and multiplies the values together. You can assume that all keys are strings and all values are integers.

For example:
let testObject = {
'a': 5,
'b': 12,
'c': 3
}

productOfValues(testObject) // should return 180 because 5 12 3 = 180

Commentshotnewtop
ErickGonzalez5 (0)

function productOfValues(someObject) {

let results = 1;
for (const i in testObject) {
results = results * testObject[i];
}
return results
}

let testObject = {
'a': 5,
'b': 12,
'c': 3
}

Codejira (166)

I'm new to JS myself, but I'm pretty sure that this is not how to do it.

First of all: Delete the assignment from your code.

Then you should multiply the objects attributes inside the function and return the result.

Console-log the result in line 20.

(I'm getting the proper result, but also an => undefined.
No idea where that comes from.)

elonmaks (45)

Hi, @BritnyLain . Look at your code and find the parts of text where you write it wrong. There is an error.