Variables in JavaScript

Actually,I can not understand and do Arithmetic operations in JS. I am having difficulty in making javascript and I am not knowing in which programme I have to do this in.And whenever I do steps of console it shows error.Somebody please help to solve this problem.Please tell me what to do in https://trainings.boltiot.com/courses/429176/lectures/6577950

Please send the screenshot of what you are doing so that i can better understand your problem.

This is the code that I cannot understand and do. Whenever I open console of this webpage it shows failed.

1 Like

Like this

1 Like

In this code you have written a line src=“my-javascript.js” basically the task of this command is that it allow the current html code to load or link to another file which is defined by the line src=“my-javascript.js”. As you haven’t created my-javascript.js file and you are accessing a file that doesn’t exist. So that’s why you are getting an error. First create a file my-javascript.js then you can run your program without any error .

THANK YOU MY PROBLEM IS SOLVED.BUT NOW I AM HAVING PROBLEM IN Manipulating HTML content using JS
CAN YOU PLEASE HELP ME AGAIN.

1 Like


See it is not showing output.Please help me.

In this code you have entered the wrong name of your .js file. You have entered my-javascript.js but i can see that the actual name of .js file is manuplate.js. I think this is the reason for the error.

1 Like

THANK YOU FOR AGAIN HELPING ME
I DID THE SAME YOU TOLD ME AND I DID IT. THANKING YOU WITH RESPECT FOR HELPING ME AGAIN.
with respect

1 Like

Actually i thank you for asking the doubt. Because solving others doubt helps me to brush up my knowledge.

1 Like

Variables in Javascript
I am also getting the error. But I am not able to resolve. Can you help me out?!

Can you share the screenshot of your JavaScript file?

Thanks for your response. But I already got a solution for my query.

1 Like

Hello @pathak.shreyas.s
Don’t worry about this problem. I hope, I would help you. Have faith and try once again as I suggest you below.
step1: Open Sublime text and write the below program and save it as my-javascript.js
var c = 3 + 4; // Addition operation on numbers.
console.log ("The value of c is ", c);
var x = 2;
var y = 3;
var z = x - y; // Subtraction operation on variables.
console.log ("The value of z is ", z);
var m = x * y; // Multiplication operation on variables.
console.log ("The value of m is ", m);
var n = x / y; // Division operation on variables.
console.log ("The value of n is ", n);
var w = (x * y + 20) - 10 // Arithmetic operation on an expression.
console.log ("The value of w is ", w);
step2: Open a new file in the sublime text and write the below program and save with .html extension

<html>
    <head>
    <title>Javascript Variables</title>
    <script type="text/javascript" src="my-javascript.js"></script>
    </head>
    <body>
    </body>
</html>

step3: Now go to the folder in which you have saved your html file and right click on it and select open with google chrome
step4: Now you can see a blank page open on your laptop. Right click on the page and go to inspect and then go to console there you can see your output
NOTE: 1. Save the first code as my-javascript.js because in html code we wrote the program src=“my-
javascript.js”> which interlinks HTML code with javascript . when we write this code
in html the javascript is processed and output is shown.
2.Open HTML file in Google Chrome because some other browsers may not have access to js
code.
Hope you can understand this and let me know if you face any problems further.

2 Likes