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
9 Answers
+ 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.
+ 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.
+ 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
+ 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.
+ 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
+ 2
Okay ODLNT
Thanks for confirmation, I got it đ
+ 1
It works for me. Do you not see any output or was there any error message?
+ 1
Ipang there is no output.
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.