Trouble with final “Words” Project on JavaScript | Sololearn: Learn to code for FREE!

0

Trouble with final “Words” Project on JavaScript

I’ve been trying to figure this out and have read and reread all of Ecma 6 and I’m still lost. Here’s the code I tried and I’ve tried many others but I feel like I have no general direction for what I’m doing. class Add { constructor(...words) { this.words = words; } //my code here print() { Add.forEach(words => { console.log("$"); }) } //my code above var x = new Add("hehe", "hoho", "haha", "hihi", "huhu"); var y = new Add("this", "is", "awesome"); var z = new Add("lorem", "ipsum", "dolor", "sit", "amet", "consectetur", "adipiscing", "elit"); x.print(); y.print(); z.print();

2/6/2021 2:13:40 AM

Mark

6 Answers

New Answer

+2

what are you expecting as output? because your code doesn't help us to understand... :(

+1

sorry, the output is supposed to output every word for every variable with a dollar sign before and behind it. Ex: $this$is$awesome$

+1

print() { console.log(☆$'+this.words.join('$')+'$'); }

+1

https://code.sololearn.com/WsNxEbgiZKUj/?ref=app

0

class Add { constructor(...words) { this.words = words; } //my code here print() { this.words.forEach(word => { console.log(`$${word}`); }) } } //my code above var x = new Add("hehe", "hoho", "haha", "hihi", "huhu"); var y = new Add("this", "is", "awesome"); var z = new Add("lorem", "ipsum", "dolor", "sit", "amet", "consectetur", "adipiscing", "elit"); x.print(); y.print(); z.print(); you forgot to close class Add , didnt put this.words in forEach

0

for either adjustment to the codes that were suggested, i get the same syntax error saying that var x = new Add is an unexpected identifier.