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
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.)
Hi, @BritnyLain . Look at your code and find the parts of text where you write it wrong. There is an error.
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
}