What is wrong with this javascript code | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок
0

What is wrong with this javascript code

var myFunction = function (str, n) { var string = "" ; for(x=0;x<str.length;x++) { string = string + str[x].repeat(n) } return string; } console.log(myFunction("hello again",5 ) )

27th Aug 2019, 8:03 AM
Promise
Promise - avatar
15 ответов
+ 3
var myFunction = function (str, n) { var string = "" ; for(x=0;x< n; x++) { string = str.repeat(n) } return string; } console.log(myFunction("hello again ",5 ) )
27th Aug 2019, 8:12 AM
Bahhaⵣ
Bahhaⵣ - avatar
+ 1
it works fine, I tested it before posting it. here is even a simpler version. var myFunction = function (str, n) { return str.repeat(n) } console.log(myFunction("hello again ",5 ) )
27th Aug 2019, 9:08 AM
Bahhaⵣ
Bahhaⵣ - avatar
+ 1
SoloLearn playground. add it to a web project and paste the code in the Js section and run it.
27th Aug 2019, 9:13 AM
Bahhaⵣ
Bahhaⵣ - avatar
+ 1
that's weird, it works fine. where did you test it and how exactly?
27th Aug 2019, 9:17 AM
Bahhaⵣ
Bahhaⵣ - avatar
+ 1
post it to your codes and make it public so I can check it out.
27th Aug 2019, 9:22 AM
Bahhaⵣ
Bahhaⵣ - avatar
+ 1
it worked fine, it output hello again 5 times. are you testing it on a mobile phones or web browser?
27th Aug 2019, 9:31 AM
Bahhaⵣ
Bahhaⵣ - avatar
+ 1
Android or IOS? I tested it on android and Firefox it works. I don't know what could be the problem in your end.
27th Aug 2019, 9:40 AM
Bahhaⵣ
Bahhaⵣ - avatar
0
I inputed your code into sololeq playground and it still gave me error. It didn't work
27th Aug 2019, 9:00 AM
Promise
Promise - avatar
0
Where did u test it? On which editor?
27th Aug 2019, 9:11 AM
Promise
Promise - avatar
0
I tested it and it told me Uncaught type error. undefined is not a function line 4 (line 4 is were the return statement is)
27th Aug 2019, 9:14 AM
Promise
Promise - avatar
0
I tested it in SOLOLEARN play ground. Under javascript. What do u think is wrong? Why would a good code tell me Uncaught error
27th Aug 2019, 9:19 AM
Promise
Promise - avatar
0
It's public
27th Aug 2019, 9:27 AM
Promise
Promise - avatar
0
I am testing it on my mobile phone
27th Aug 2019, 9:37 AM
Promise
Promise - avatar
0
I use android as well. I have been noticing the problem. But I don't know were its coming from
27th Aug 2019, 9:41 AM
Promise
Promise - avatar
0
It's really frustrating
27th Aug 2019, 9:41 AM
Promise
Promise - avatar