r/JavaScriptTips • u/mnqundu-wakho-234 • Jan 21 '23
debugging this JavaScript code Good day everyone. I am currently learning JavaScript, I started 2 months ago. I humbly request your assistance in debugging the code below. I tried watching YouTube but I couldn't get any assistance. So the code is supposed to out BAART! Eat my shorts ! O'oh! Bu
3
Upvotes
1
u/Banzaye Jan 27 '23 edited Jan 27 '23
You don't need to run a for loop if you are passing only certain phrases:
const phrases = { a: 'Hello', b: 'World', c: '!' }
function printPhrases(one, two, three) { console.log(one + ' ' + two + ' ' + three) }
printPhrases(phrases.a, phrases.b, phrases.c)
If you don't want to be limited in your arguments you can use:
const phrases = { a: 'Hello', b: 'World', c: '!' }
const printPhrases = (...args) => { args.forEach(arg => console.log(arg.toString())) }
printPhrases(phrases.a, phrases.b, phrases.c)
3
u/slam_the_damn_door Jan 21 '23
Line 21 - 'lisa', 'bart', 'homer' should be an array not individual strings.
Line 14 - console log you need to key the variable jsObject with the element at the ith position of the passed keys array.
Idk what your trying to do on line 18. If you remove it that should run.