How to use Console.log

Hello there,
I am new in coding world. I am trying to run this following code
but it is not working in my browser. I use opera browser and sublime as my text editor.

var myArray = ["a", "b", "c"];
myArray.push("d");
console.log(myArray);

//// code ends here/////
1 Like

Code looks good and worked for me in Chrome. Maybe try a different browser?
-J

I tried it in Mozilla Firefox but it is not working. Any other suggestion you can help me with?
Can you please send me the screenshot of your code and the screenshot of your browser? browser o

you don’t need to use backticks everywhere- only around code
it is difficult to read long texts written in monospace

it depends on how you are using the editor. are you running the code?

for example I usually use repl.it, which is different, here you don’t have the code output automatically updating like in freecodecamp, but you have to press “Run” for the code to run

1 Like

How exactly are you trying to run this code? Is this code located in a <script> tag in an HTML file or a standalone .js file?

1 Like

Yes I am doing it but result stills same. But right now I just figured out in Mozilla Firefox that if I go to web developer option and then click the console option and write the code in the console box the result is showing like I wanted. But I want this code to run through my text editor which will show result in my browser.

I created an HTML file and then link my .js file. But right now I just figured out in Mozilla Firefox that if I go to web developer option and then click the console option and write the code in the console box the result is showing like I wanted. But I want this code to run through my text editor which will show result in my browser.

That should be correct. Can you post the code of the HTML file you are using? Have you refreshed the page after saving your code?

1 Like
<!DOCTYPE html>
<html>
<head>
	<title></title>
</head>
<body>
	<script type="text/javascript" src="day_7.js"></script>

</body>
</html>

//////JS File////

var myArray = [“a”, “b”, “c”];
myArray.push(“d”);
console.log(myArray);

I have copied your code as is to my editor as index.html and day_7.js and it seems to be working fine. Does your developer console not show any output at all when you refresh? Have you made sure your JS file is named correctly?

Edit: Screenshot

1 Like

Sorry to knock you again. Please Have a look at this. I have refreshed it and checked it several times and it is named correctly.

Maybe this article will help:

You have put the JavaScript file ‘day_7.js’ and the html file ‘day_7.html’ in the same folder, right?

1 Like

Thanks a lot for your reply. I figured out my error already.