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
5 Antworten
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);
}
}
+ 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.
+ 1
Thanks..
I've edited the question to include a link to the code
+ 1
Thanks a lot
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')
}