4th Mar 2021, 6:04 PM
kalungi robert
kalungi robert - avatar
4 Answers
+ 1
class Add { constructor(...words) { this.words = words; } print() { return "
quot; + this.words.join("
quot;)+ "
quot;; } } 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(); Can anyone tell me were the problem is
4th Mar 2021, 6:08 PM
kalungi robert
kalungi robert - avatar
+ 1
When running the code in the code coach, you should notice there is no output. That is because you are only returning the strings, but never actually printing them. You can use console.log() to print the returned strings, e.g. console.log( x.print() ); ... or do it directly from the print() method.
4th Mar 2021, 6:13 PM
Shadow
Shadow - avatar
+ 1
OK thanks
4th Mar 2021, 6:44 PM
kalungi robert
kalungi robert - avatar
0
. declare array of Strings in Add class with name: words . rename constructor with name same as class name . add type String to constructor parameter . add return type for print() . do join by this way +String.join("
quot;, words) . there is no main() method . usually print is System.out.println()
4th Mar 2021, 10:08 PM
zemiak
Hot today
Help please?
3 Votes