I would like to know, how I can write this in one line with the symbol of dollar($) separating each word and with this symbol in the end?I've tried to change " " to $ with replace - no success. In this example it is printing $ before every word but still in a column :/
class Add {
constructor(...words) {
this.words = words;
}
print() {
var a = this.words;
for (let v of a) {
v = "$" + v;
console.log(v);
}
}
}
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();
Unless you need the object for other things, put the strings in an array and use array.join() with '$' as the join argument, and concatentate ? to the end.
Working snippet:
let x = ["hehe", "hoho", "haha", "hihi", "huhu"];
console.log(`${x.join('$')}?`);