I need help

hi guys why this code doesnt work ?

function sayThanks(){
  console.log ('Thank you for your purchase! We appreciate your business.')
}
sayThanks(.repeat(3))

it says = .repeat is not a function

String.prototype.repeat() - JavaScript | MDN

 > function foo() {
       return "Ah, foo!\n"
   }
<- undefined
 > console.log(foo().repeat(3))
   Ah, foo!
   Ah, foo!
   Ah, foo!
<- undefined
 > 

ok
i didnt undrestand fully

1 Like

can you explain me more
and how can i use it in my code without using (console.log)

Did you read the page about String.repeat()? Note that .repeat() is a String method. Above we have the function return the string and we use .repeat() in the argument for console.log() to call the function three times.

If you don’t log the strings, how will they be outputted?

1 Like

thansk , i read it but i didnt paid enough attention

1 Like

hi again
i think i didnt fully undrestood the .repeat
look at this code

function monitorCount(rows, columns) {
  return rows * columns;
}
const numOfMonitors = monitorCount(5, 4);

console.log(numOfMonitors.repeat(5));

doesnt work
this is the error = TypeError: numOfMonitors.repeat is not a function

.repeat() must be called on a string. Recall their prior example:

this works because foo() is getting called and returning a string. After considering the function call it is equivalent to

console.log(("Ah, foo!\n").repeat(3))

In your code, you could make use of the Number method .toString() in order to be able to use .repeat()

1 Like