Repeat a given string str (first argument) for num times (second argument). Return an empty string if num is not a positive number. For the purpose of this challenge, do not use the built-in .repeat() method. "
So far I have:
function repeatStringNumTimes(str, num) {
let repeatedString = “”;
for (let i = 0; i < 0; i += 1) {
let (repeatedString === repeatedString*(num));
}
return repeatedString;
}
I figured I would set the repeatedString equal to itself times whatever num…then the repeated string would repeat as many times as the num’s value. But I know my logic is off.
function repeatStringNumTimes(str, num) {
// ^^^you are not using the str parameter at all
// which holds the string to be repeated n times
let repeatedString = "";
for (let i = 0; i < 0; i += 1) {
// ^^^will this loop ever run?
// is i ever less then 0?
// if this loop never runs any code in this block will also not run
let (repeatedString === repeatedString*(num));
// ^^^the console should be giving you an syntax error for this
// you are using let which is used to declare a variable, but not making a variable
// you cant just * the string like this in javascript to repeat it
// and repeatedString is also just an empty string right now
// and === is a comparison operator
// its not putting the repeated string into your variable
}
return repeatedString;
}
Try fixing that for loop first. Then when you get that working try building that string up in your repeatedString variable.