+ 4
Words: Code Project
[SOLVED] You are making a text encryptor. It should take multiple words and output a combined version, where each word is separated by a dollar sign $. For example, for the words "hello", "how", "are", "you", the output should be "$hello$how$are$you
quot;. The given code declares a class named Add, with a constructor that takes one rest parameter. Complete the code by adding a print() method to the class, which should generate the requested output. https://code.sololearn.com/ctNMpxae1NX5/?ref=app9 odpowiedzi
+ 5
You're missing the "quot; at the end of each line.
Replace line 12:
console.log("quot; + this.words.join ("quot;, x, y, z, "quot;));
with:
console.log("quot; + this.words.join ("quot;, x, y, z, "quot;) + "quot;);
+ 6
Mafdi I commented out my own code and then pasted yours and it gave me a long error. I’ll test it again. Thank you.
+ 5
Simon Sauter I think this makes sense to me now. $ at beginning and end of the outer () and also $ at beginning and end of inner () of the printout. Thank you for saving the day. I thought I might never finish this course. 🤝
+ 4
Mafdi I erased my winning code and pasted the one you entered above that begins with the class declaration. This time it told me I’m on 🔥and threw 🎉. So yes, you have an alternative winning code. Thank you 🙏.
+ 3
// I am not an expert in Javascript and I forgot many of it's lessons
// I just made this project now to help you
// there can be many different ways to solve it
//your code goes here
print () {
let out_words = "quot;;
let len = this.words.length;
for (let i = 0; i < len; i++) {
out_words += this.words[i] + "quot;;
}
console.log(out_words);
}
/*
1. you start by the $ sign
2. then you loop the array
3. you concatenate to the string an array item and a $ sign
4. then output the complete string
*/
+ 3
Mafdi I thank you for your offer of help. Your code gave a syntaxError that has a ^ under the fourth letter in the string “hihi”.
+ 2
For the love of my sanity…
I see two missing $ in the output. There has to be a $ before and after each string. Why is mine missing two $?
I’ve tried numerous changes, none of which work.
+ 2
it solved the last project of Javascript course
+ 1
class Add {
constructor(...words) {
this.words = words;
}
//your code goes here
print () {
let out_words = "quot;;
let len = this.words.length;
for (let i = 0; i < len; i++) {
out_words += this.words[i] + "quot;;
}
console.log(out_words);
}
}
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();