+ 3
JavaScript Code coach problem...I am not actually able to get what am I supposed to do in this question?????
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". 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. Note, that the dollar sign is placed at the beginning and at the end of the output...... My try https://code.sololearn.com/Wd5b1xcAs906/?ref=app
28 Réponses
+ 11
Hi there.. your not supposed to write code outside of the class. Write your code where it says your code goes here.
Also try to use join function.
Or, go through each word and print dollar sign,then word.
After the loop finish print a dollar sign
here's my code...
https://code.sololearn.com/cJgucC7EXB2f/?ref=app
+ 49
class Add {
constructor(...words) {
this.words = words;
}
//your code goes here
print(){
var y ="";
for (x of this.words) {
if(x == ","){
x = "";
}
else{
y += "quot; + x;
}
}
y = y + "quot;;
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();
+ 13
//your code goes here
print(){
var res="";
for(var i=0;i<this.words.length;i++){
res += "quot;+this.words[i];
}
console.log(res+"quot;);
}
+ 9
class Add {
constructor(...words) {
this.words = words;
}
//my code
print(){
console.log(`${this.words.join('#x27;)}
)
}
}
+ 4
Ans
class Add {
constructor(...words) {
this.words = words;
}
//your code goes here
print(){
var y ="";
for (x of this.words) {
if(x == ","){
x = "";
}
else{
y += "quot; + x;
}
}
y = y + "quot;;
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();
+ 3
Steve Sajeev
Thank you So much for the help
I got what you explained me
Thanks Steve for the answer
+ 3
class Add {
constructor(...words) {
this.words = words;
}
//your code goes here
print(){
var y ="";
for (x of this.words) {
if(x == ","){
x = "";
}
else{
y += "quot; + x;
}
}
y = y + "quot;;
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();
Good Luck
+ 2
class Add {
constructor(...words) {
this.words = words;
}
//your code goes here
print(){
var y ="";
for (x of this.words) {
if(x == ","){
x = "";
}
else{
y += "quot; + x;
}
}
y = y + "quot;;
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();
+ 1
ᕙ(@°▽°@)ᕗ {inactive}
I tried your method
But still it is showing test case failed Bhai...
Can you please tell what we are actually supposed to do in this question?
+ 1
class Add {
constructor(...words) {
this.words = words;
}
print(){
var result ="";
for (let word of this.words) {
result += "quot;+word;
}
result += "quot;;
console.log(result);
}
}
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();
+ 1
this my solution.
class Add {
constructor(...words) {
this.words = words;
}
//your code goes here
print(){
let result=""
for (const e of this.words) {
result+="quot;+e
}
console.log(result+"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();
+ 1
class Add {
constructor(...words) {
this.words = words;
}
//your code goes here
print(){
var new_T = "";
for(let i=0;i<this.words.length ; i++){
new_T += "quot; + this.words[i];
}
console.log(new_T+"quot;);
}
}
+ 1
print(){
let res="quot;;
let w=this.words;
for(let v of w){
res +=v+"quot;;
}
console.log(res);
}
+ 1
class Add {
constructor(...words) {
this.words = words;
}
//your code goes here
print(){
var y ="";
for (x of this.words) {
if(x == ","){
x = "";
}
else{
y += "quot; + x;
}
}
y = y + "quot;;
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();]
+ 1
print(){
var y ="";
for (x of this.words) {
if(x == ","){
x = "";
}
else{
y += "quot; + x;
}
}
y = y + "quot;;
console.log(y);
}
}
Try this☺️
+ 1
You can also write it in this way with the for.. of iterator.
print(){
var res = "";
for(let w of this.words){
res += "quot;+w
}
console.log(res+"quot;)
}
+ 1
class Add {
constructor(...words) {
this.words = words;
}
//your code goes here
print(){
let res="";
for(let i=0; i< this.words.length;i++){
res=res+("quot;+this.words[i]);
}
console.log(res+"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();
0
welcome
0
class Add {
constructor(...words) {
this.words = words;
}
//your code goes here
print(){
var y ="";
for (x of this.words) {
if(x == ","){
x = "";
}
else{
y += "quot; + x;
}
}
y = y + "quot;;
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();
0
@vlad
your solution is the simplest :)