Basic JavaScript - Subtract One Number from Another with JavaScript

Tell us what’s happening:
Describe your issue in detail here.

Your code so far

const myVar = 45 - 24;
var myVar = 12 - 6;

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:105.0) Gecko/20100101 Firefox/105.0

Challenge: Basic JavaScript - Subtract One Number from Another with JavaScript

Link to the challenge:

You don’t want to add any new lines of code. The only thing you want to do is change the 0 in the original code to another number so that the variable difference is set to 12.

  • The variable difference should be equal to 12.

Failed: You should only subtract one number from 45.

Did you fix the code so there is only the original line? Did you change the original 0 to another number? I have no idea how to help you since I don’t know what you did. Please paste your updated code in here so we can see.

To display your code in here you need to wrap it in triple back ticks. On a line by itself type three back ticks. Then on the first line below the three back ticks paste in your code. Then below your code on a new line type three more back ticks. The back tick on my keyboard is in the upper left just above the Tab key and below the Esc key. You may also be able to use Ctrl+e to automatically give you the triple back ticks while you are typing in the this editor and the cursor is on a line by itself. Alternatively, with the cursor on a line by itself, you can use the </> button above the editor to add the triple back ticks.

Subtract One Number from Another with JavaScript

We can also subtract one number from another.

JavaScript uses the - symbol for subtraction.

Example

const myVar = 12 - 6;

myVar would have the value 6.


Change the 0 so the difference is 12.

Use the “Reset All Code” button to get the original JS back. You should see:

const difference = 45 - 0;

Do not make any changes other than changing the 0 to the appropriate number so that difference is set to 12.

// running tests The variable

difference

should be equal to 12. You should only subtract one number from 45. // tests completed

I’m sorry, I don’t know how to help you. You have to show us your updated code every time you make a change so we can see what you did.

const difference = 45 - 22;

Are you sure that equals 12?

const difference = 45 - 6;

This equals 39. I think you need to increase the second number quite a bit to get it down to 12. Use a calculator to make sure you get it right.

I’m not good at math

There is a website called khanacademy.org that teaches math skills for all grade levels. Or you can learn how to use a calculator to do maths as needed.