Fundamental 4 - Javascript-Excercises-repeatString

Hi,

I am trying to do the TDD exercises in Javascript, but stuck at the repeatString exercise as jasmine gives a failure the code.
The code works perfectly fine when I tried it on ‘codepen’, but jasmine gives and error.

my code:
const repeatString = function(greeting, num) {
if (num < 0) return ‘ERROR’
let str = ’ ';
for (let i = 0; i < num; i++) {
str += greeting;
}
return str;
}

Hey @sowmya1408

What’s the failure you are getting?

Expected ' heyheyhey' to equal 'heyheyhey'.

Looks like you initialise the string with a space.

let str = ' ';

Remove the space and it should work.

Yes… I did that and now it works perfectly fine :smile:

Thank You!!

1 Like

I am trying to learn JavaScript and looking for the best course. I did some research on google and found this list of JavaScript courses.https://bit.ly/2H7z3cP ,but I am still confused which one I should start? Any suggestion please… ( Thanks in advance)

Hey Yuresh_Shayzer: Doing the Web Development 101 course here in the the Odin Project is a great way to learn the basics of Javascript. And there are always suggestions at the bottom of the chapters if you need more material to deepen your understanding. I did other JS tutorials and courses before. But for me personally I have the best learning experience here in TOP. I think they did a great job to structure the material and give you the best learning experience possible.