+ 6
JavaScript last project(Words)
I can’t seem to solve this challenge. It seems like its impossible, I did every iteration there is possible. Can someone help me solve it? You can look the challenge in my profile(Challenge section draft). class Add { constructor(...words) { this.words = words; } //your code goes here print(){ var wtf=""; for(var i=0; i<this.words.length; i++){ wtf+="
quot;+this.words[i]; } console.log(wtf); } } 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();23 odpowiedzi
+ 9
You need to add another dollar sign at the end of each line, like the note next to the exclamation mark at the end of the exercise suggests. The example in the description seems to be incorrect in this regard.
+ 20
Ofc you can use loops here, but in this case it's not nessesary.
class Add {
constructor(...words) {
this.words = words;
}
print() {
var s = this.words.join('#x27;); //step 1
console.log('#x27;+s+'#x27;); //step 2
}
}
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();
+ 12
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();
+ 2
class Add {
constructor(...words) {
this.words = words;
}
//your code goes here
print()
{
let newstring ="";
for(let i=0 ; i< this.words.length ; i++ )
{
newstring = newstring + '#x27; + this.words[i] ;
}
newstring = newstring + '#x27; ;
console.log(newstring) ;
}
}
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
My solution.
print() {
let crypto = "quot;;
this.words.forEach((w) => crypto += w + "quot;);
console.log(crypto);
}
+ 1
i can't solve this project
+ 1
UIUUUUU OKEY THANK YOU!!!!!
+ 1
This works too and it's just one line
class Add {
constructor(...words) {
this.words = words;
}
print(){
console.log('#x27; + this.words.join('#x27;)+'#x27;)
}
}
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
Some of the JavaScript solutions that work on fiddle, or on Webmaker do not work on SoloLearn. Maybe some server differences.
0
My code is quite simple but works just fine:
class Add {
constructor(...words) {
this.words = words;
}
print() {
const wordsWithDolars = this.words.map(word=>`${word}
);
const reducedWordsWithDolars = wordsWithDolars.reduce((acc,currentValue)=>acc+currentValue,'#x27;);
console.log(reducedWordsWithDolars);
}
}
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
Your code is right. Just need to hardcode an $ un the last place. Right after the loop.
0
class Add {
constructor(...words) {
this.words = words;
}
//your code goes here
print() {
var _words = "";
for (var i = 0; i < this.words.length; i++) {
_words += "quot; + this.words[i];
if(i == this.words.length -1){
_words += "quot;;
}
}
console.log(_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();
0
use the join method
0
I can’t seem to solve this challenge. It seems like its impossible, I did every iteration there is possible. Can someone help me solve it?
You can look the challenge in my profile(Challenge section draft).
class Add {
constructor(...words) {
this.words = words;
}
//your code goes here
print(){
var wtf="";
for(var i=0; i<this.words.length; i++){
wtf+="quot;+this.words[i];
}
console.log(wtf);
}
}
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
This is how i solved that:
class Add {
constructor(...words) {
this.words = words;
}
//your code goes here
print() {
let len = this.words.length;
let otp = "";
let col = "";
let i = 0;
for (i = 0; i < len; i++) {
let otp = this.words[i] + "quot;;
col += otp;
}
console.log("quot; + col);
}
}
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
I have try this too the outputs are corrects but its showing me no input pls someone help
class Add {
constructor(...words) {
this.words = words;
}
//your code goes here
print() {
for(let word of this.words){
console.log("quot;+word+"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
class Add {
constructor(...words) {
this.words = words;
}
print() {
let line = "";
for(let k =0; k< this.words.length ; k++){
line += "quot; + this.words[k];
}
console.log(line + "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
class Add {
constructor(...words) {
this.words = words;
}
print(){
console.log("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();
0
Solved:
class Add {
constructor(...words) {
this.words = words;
}
//your code goes here
print() {
console.log('#x27;+this.words.join('#x27;)+'#x27;);
};
}
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
My example is also good, just learn array .join() method:
class Add {
constructor(...words) {
this.words = words;
}
//your code goes here
print() {
console.log('#x27;+this.words.join('#x27;)+'#x27;);
}
}
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();