Words project
My code class Add { constructor(...words) { this.words = words; } //your code goes here print(){ var y =""; for(x of this.words){ y += `$${x}`; } console.log(y); } } 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(); It's showing error why don't know, test is also locked
12/17/2020 11:50:01 AM
Emmanuel Osemudiamen
17 Answers
New AnswerThere was a recent update to the supplied code, and it breaks older attempts. My old code once passed, but now fails. For the correction see my full explanation in this post. https://www.sololearn.com/Discuss/2630096/?ref=app
print = function (){ const myWords = []; for(let i = 0; i <= this.words.length; i++) { myWords.push("$") myWords.push(this.words[i]); } const mySentence = myWords.join("") console.log(mySentence) }
Words project My code class Add { constructor(...words) { this.words = words; } //your code goes here print(){ var y =""; for(x of this.words){ y += `$${x}`; } console.log(y); } } 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(); carrieforle like this ?
I mean, add "$" after every sentence you logged. For example, x.print() should output "$hehe$hoho$haha$hihi$huhu$". But yours is "$hehe$hoho$haha$hihi$huhu". See the difference?
My code class Add { constructor(...words) { this.words = words; } //your code goes here print(){ var y =""; for(x of this.words){ y += `$${x}`; } console.log(y); } } var x = new ($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(); It's showing error why don't know, test is also locked
I mean. In your code: var x = new Add("hehe", "hoho", "haha", "hihi", "huhu"); x.print(); The output will be "$hehe$hoho$haha$hihi$huhu". BUT, the output SoloLearn wants is: "$hehe$hoho$haha$hihi$huhu$" Modify your print() and get the output SoloLearn desired. Everything outside of your print() originally is doing great. No need to modify them.
Words project My code class Add { constructor(...words) { this.words = words; } //your code goes here print(){ var y =""; for(x of this.words){ y += `$${x}`; } console.log(‘$y$’); } } 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(); It's showing error why don't know, test is also locked