0

ES6 Objects, Workout Harder

You are making a workout app. After completing the basic exercises in the app, the user is able to access advanced content. The given program declares two classes - basic and advanced with corresponding properties. Complete the code to combine basic and advanced level exercises into one new object named total, so that the given code for final output works correctly. Code: let basic = { ex1: 'PushUps: 20 times', ex2: 'Jumps: 20 times' }; let advanced = { ex3: 'Squats: 30 times', ex4: 'Run: 2km' }; //your code goes here for(let ex in total) { console.log(total[ex]) }; I attempted this a few times, but the output is "hidden" so I can't even see what type of mistakes I'm making. Would be great if someone could help me out.

21st Jul 2021, 4:56 PM
Jacob Kimbrell
Jacob Kimbrell - avatar
8 Antworten
+ 6
I only posted because I put this and it didn't work, I just did it again and it worked fine. Appreciate it. let basic = { ex1: 'PushUps: 20 times', ex2: 'Jumps: 20 times' }; let advanced = { ex3: 'Squats: 30 times', ex4: 'Run: 2km' }; //your code goes here let total = Object.assign({}, basic, advanced); for(let ex in total) { console.log(total[ex]) };
21st Jul 2021, 5:16 PM
Jacob Kimbrell
Jacob Kimbrell - avatar
+ 4
const total = {...basic, ...advanced}; Also this let total = Object.assign({}, basic, advanced); should be working fine too https://code.sololearn.com/cz4WqzPJqBcN/?ref=app
22nd Jul 2021, 4:14 AM
Calviղ
Calviղ - avatar
+ 2
//Please Subscribe to my youtube channel //channel name: Fazal Tuts4U let basic = { ex1: 'PushUps: 20 times', ex2: 'Jumps: 20 times' }; let advanced = { ex3: 'Squats: 30 times', ex4: 'Run: 2km' }; const total = Object.assign({}, basic, advanced); for(let ex in total) { console.log(total[ex]) };
5th Sep 2021, 5:39 PM
Fazal Haroon
Fazal Haroon - avatar
+ 1
let basic = { ex1: 'PushUps: 20 times', ex2: 'Jumps: 20 times' }; let advanced = { ex3: 'Squats: 30 times', ex4: 'Run: 2km' }; //your code goes here let total = Object.assign({}, basic, advanced); for(let ex in total) { console.log(total[ex]) }; Good Luck
25th Jan 2022, 8:51 AM
Muhammad Alif Deva Rizqon
Muhammad Alif Deva Rizqon - avatar
0
Please save your whole code on SL Playground and link here and ask you question. So is more better to help you.
21st Jul 2021, 5:08 PM
JaScript
JaScript - avatar
0
Luci You need to join both objects then assign to a variable total. Use Object.assign to join objects.
21st Jul 2021, 5:12 PM
A͢J
A͢J - avatar
0
let basic = { ex1: 'PushUps: 20 times', ex2: 'Jumps: 20 times' }; let advanced = { ex3: 'Squats: 30 times', ex4: 'Run: 2km' }; let total = Object.assign({}, basic, advanced); for(let ex in total) { // can someone explain what exactly do this ??? console.log(total[ex]) };
21st Nov 2021, 12:57 AM
Noel Gil
Noel Gil - avatar
0
Noel Gil Object.assign will join two objects into a single object so here total is a combined object of both objects. for(let ex in total) // this is known as enhanced for loop and here ex "in" means we are getting key of each data in object total now total[ex] will print value corresponding each key if you print ex then you will get ex1, ex2, ex3, ex4
21st Nov 2021, 1:05 AM
A͢J
A͢J - avatar