I am trying provide a function (wrap) that inserts a value into an object in JS and return that value. So if wrap('mystring') is called, 'mystring' should be returned. If wrap(345) is called, 345 (I believe as an integer) should be called and so on and so forth (don't think I need to return an array).
I just want to put the value inside of an object and then to return that value. So the object should be {key: 10} or {key: 'Mine'} and just return the value itself (so return 10 as an integer or return 'Mine" as a string ).
This is my code:
function wrap(value) {
let obj = {}
const key = value;
obj[key] = value;
return obj
}
Test Passed: Value == 'object';
Expected: 'MyTest', instead got: undefined;
Expected: 343, instead got: undefined;
Expected: { test: 'testy' }, instead got: undefined;
These are the tests, and three of the tests are not passed.
Any help is appreciated, Thank you
CodePudding user response:
Your function works i have this
function wrap(value) {
let obj = {}
// const key = value;
// obj[key] = value;
obj['key'] value;
return obj
}
console.log(wrap(10))
// returns {key: 10}
console.log(wrap('Mine')
// returns {key: 'Mine'}
It this clearly what you want to do ? Just define the function doesn't execute it.