+ 1
4 Réponses
+ 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
+ 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.
+ 1
OK thanks
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()