- 3

Why I m not getting any output

var dog = 20; var cat = 5050; document.write(dog + cat); //not getting output

1st Jan 2022, 6:34 PM
Nikhil
Nikhil - avatar
12 Respuestas
+ 6
document.write is not in node.js, it's in standard Javascript, so you're mixing incompatible code. For that, you need to change document.write to console.log instead
2nd Jan 2022, 2:29 AM
Simba
Simba - avatar
+ 1
It seems to work fine for me. Perhaps there is something wrong with the environment you are running it in. Is it possible I could know where in order to help?
1st Jan 2022, 6:44 PM
Kamil Hamid
Kamil Hamid - avatar
0
I have runned in solo learn node.js
1st Jan 2022, 6:48 PM
Nikhil
Nikhil - avatar
0
The problem is due to saying document.weite, because in node.js (in SoloLearn at least) it cannot run that. Try running it in web in SoloLearn (in the tab Javascript)
1st Jan 2022, 6:50 PM
Kamil Hamid
Kamil Hamid - avatar
0
Thank you for your help. But I also checked in spck pro app in my mobile in that also getting error
1st Jan 2022, 6:52 PM
Nikhil
Nikhil - avatar
0
Have you executed that in a node.js environment as well?
1st Jan 2022, 6:53 PM
Kamil Hamid
Kamil Hamid - avatar
0
Yes
1st Jan 2022, 6:54 PM
Nikhil
Nikhil - avatar
0
So that must be the problem. Node.js environments cannot be used to run this code as it uses document.write, which is used for web pages. So therefore it can only be executed in web documents (or in the script tag of a html document)
1st Jan 2022, 6:55 PM
Kamil Hamid
Kamil Hamid - avatar
0
It's bizarre that we can't use '//' but '/**/' as the comment.
1st Jan 2022, 7:01 PM
FanYu
FanYu - avatar
0
That means thare is lots of difference between javascript and node.js
2nd Jan 2022, 4:34 AM
Nikhil
Nikhil - avatar
0
Yes, as one is more file based while the other (node.js) is more console based
2nd Jan 2022, 12:45 PM
Kamil Hamid
Kamil Hamid - avatar
0
Thanks for ur help
4th Jan 2022, 3:03 AM
Nikhil
Nikhil - avatar