0

Hi.. I'm having troubles with the last code project on the JavaScript course "words" on ECMASCRIPT.

I need assistance on how to go about solving the code. Any help would be greatly appreciated. Thanks https://code.sololearn.com/WvqDjE7ndOS1/?ref=app That's the link to the code... Thanks

23rd Nov 2022, 10:19 PM
Joshua Ukaka
Joshua Ukaka - avatar
5 Answers
0
Joshua Ukaka 1.you did not place a closing bracket in your class definition. 2.print is a class method, so write it as such. 3. you are iterating this.words, not Add. 4. use for-of instead of for-in. 5.Console log will automatically add a newline at the end, so you have to build the output string first, otherwise the words will be on separate lines. class Add { constructor(...words) { this.words = words; } //your code goes here print(){ let result = "
quot;; for(let i of this.words) result += i+"
quot;; console.log(result); } }
27th Nov 2022, 12:51 AM
Bob_Li
Bob_Li - avatar
+ 6
Can you post your code? You would learn better if we help you debug your code rather than if I just gave you a solution. Active learning is better than passive learning. You have almost finished the lesson, so it is just applying previous knowledge.
24th Nov 2022, 2:32 AM
Bob_Li
Bob_Li - avatar
+ 1
Thanks.. I've edited the question to include a link to the code
26th Nov 2022, 5:26 PM
Joshua Ukaka
Joshua Ukaka - avatar
+ 1
Thanks a lot
28th Nov 2022, 3:05 PM
Joshua Ukaka
Joshua Ukaka - avatar
0
Joshua Ukaka Alternatively, you can use process.stdout.write, which does not add a new line. So you can iterate directly and add the final $ and \n at the end. print(){ for(let w of this.words) process.stdout.write(`${w}`) process.stdout.write('$\n') }
27th Nov 2022, 12:57 AM
Bob_Li
Bob_Li - avatar