0

Why Javascript console not working?

I'm not sure why the JS console doesn't show the results, can anyone help? https://code.sololearn.com/WVBup8WK2s5k/#js

19th Apr 2020, 3:22 AM
Danial Azadpour
Danial Azadpour - avatar
9 ответов
+ 2
I just noticed that the code does output only when ran in SL mobile app. No output in console when running in mobile Chrome. Unfortunately I don't know why or how this is happening.
19th Apr 2020, 7:28 AM
Ipang
+ 2
Sololearn Website console will only accept type string, number and boolean. Hence objects should be converted to a string via toString() or JSON.stringify(). console.log(console.log.toString()) /edit <--- This line of code can be used to show the code that restricts the Sololearn website web console to just numbers, strings, and booleans.
19th Apr 2020, 6:18 PM
ODLNT
ODLNT - avatar
+ 2
Danial Azadpour Thats my fault for not being clear. To convert an array to string you must attach the toString() function to the end of the object or array in your case, array.toString() will convert the array to a string. console.log(console.log.toString()) reveals the script being used to log any output to the Sololearn console. Sorry for the confusion. https://code.sololearn.com/WsUJA25Pwszj/#js
19th Apr 2020, 7:54 PM
ODLNT
ODLNT - avatar
+ 2
ODLNT Just need to confirm one thing, this problem only exists in SL website? because the OP's code runs just fine as I open it in SL app.
20th Apr 2020, 2:18 AM
Ipang
+ 2
Ipang It is not a problem per se. It's just the way Sololearn Website prototyped console.log. But yes it appears to only prototyped this way on SL website. You can use console.log(console.log.toString()) to see the code
20th Apr 2020, 6:53 AM
ODLNT
ODLNT - avatar
+ 2
Okay ODLNT Thanks for confirmation, I got it 👌
20th Apr 2020, 6:54 AM
Ipang
+ 1
It works for me. Do you not see any output or was there any error message?
19th Apr 2020, 3:49 AM
Ipang
+ 1
Ipang there is no output.
19th Apr 2020, 4:51 AM
Danial Azadpour
Danial Azadpour - avatar
0
I put this in the first JS code var array = ["Hello", 1]; array.push("World"); console.log(console.log.toString(array)) and these were the results function () { var output = ''; for (var i = 0; i < arguments.length; i++) { var current = arguments[i]; if (typeof current == 'string' || typeof current == 'number' || typeof current == 'boolean') output += arguments[i] + ' '; } var outputHTML = output.replace(/\\r\<br/>/g, '<br/>').replace(/\<br/>/g, '<br/>').replace(/</g, '<').replace(/>/g, '>') + '<br/>'; window.parent.postMessage({ text: outputHTML, type: 'log' }, '*'); } Not what I expected, I just want the output of the function.
19th Apr 2020, 7:48 PM
Danial Azadpour
Danial Azadpour - avatar