Returning key/value pair in javascript
javascript, node.js
Solution
Your goal is to enrich the `obj` map with new properties in order to get `{2:4, 10:20,30:60,50:100, 100:200}`. But instead of doing that you're replacing the value of the `obj` variable with an object having only one property.
Change
obj = {original_value : doubled_value};
to
obj[original_value] = doubled_value;
And then, at the end of the loop, just log
console.log(obj);
Here's the complete loop code :
for(var i=0; i< Num.length; i++) {
var original_value = my_arr(Num[i]);
var doubled_value = doubling(original_value);
obj[original_value] = doubled_value;
}
console.log(obj);
Problem
I am writing a javascript program, whhich requires to store the original value of array of numbers and the doubled values in a key/value pair. I am beginner in javascript. Here is the program: ``` var Num=[2,10,30,50,100]; var obj = {}; function my_arr(N) { original_num = N return original_num; } function doubling(N_doubled) { doubled_number = my_arr(N_doubled); return doubled_number * 2; } for(var i=0; i< Num.length; i++) { var original_value = my_arr(Num[i]); console.log(original_value); var doubled_value = doubling(Num[i]); obj = {original_value : doubled_value}; console.log(obj); } ``` The program reads the content of an array in a function, then, in another function, doubles the value. My program produces the following output: ``` 2 { original_value: 4 } 10 { original_value: 20 } 30 { original_value: 60 } 50 { original_value: 100 } 100 { original_value: 200 } ``` The output which I am looking for is like this: ``` {2:4, 10:20,30:60,50:100, 100:200} ``` What's the mistake I am doing? Thanks.