0% found this document useful (0 votes)
8 views

JavaScript Number

Uploaded by

antei kuwute
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

JavaScript Number

Uploaded by

antei kuwute
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

JavaScript Number

//BASIC ARITHMETIC AND THE MODULO OPERATOR IN JAVASCRIPT.

//ADDING.

var a = 3+6; //this will give us a 9 because it's a basic in math

//SUBTRACTING.

var b = 6-3; //and this, will give us a 3

//MULTIPLY.

var c = 3*3; //this time, the variable will be 9

//DIVISION.

var d = 6/3; //and this will make the variable value to a 2

//MODULO.

var e = 17%4; /*now this is a modulo. it's like divisioning, but when the 4 cant divison 17, the rest is 1
right? and the result will be that 1*/

console.log(a, d, c, d, e); //this will show you all of the arithmetic value result. Also, all of these
arithmetic can give you a decimal result.

//ok and now i'll show you the combinations of the arithmetic i've just explained.

var cost = 3+5*2; //this will make the 5 multiply 2 is going to the first calculated arithmetic, and after
that process the adding arithmetic will be proceed. The result will be 13.

var cast = (2+5)*3; //now with this set of parentheses the adding arithmetic will be calculated first
and then followed by the multiply arithmetic. The result will be 21.

console.log(cost, cast); //this is the result on the console log


//btw, the parentheses () is good to used for multiply or division and modulo arithmetic too, because
with this parentheses you can make sure or recognize what process will be executed or calculated
first, even it's a multiply or a division or maybe modulo arithmetic.

//now this is the excercise that called Dog Age to Human Age Formula

var dogAge = prompt("Tell me your dog age :)");

var humanAge = ((dogAge - 2) * 4) + 21;

alert("Your dog age if it was a human is " + humanAge + ".");

console.log(humanAge);

//INCREMENT AND DECREMENT.

//INCREMENT.

var x = 6;

/*x = x+1;*/ //instead of doing x = x+1; you can do it like this:

x++;

//DECREMENT.

var y = 5;

/*y = y-1;*/ //instead of doing y = y-1; you can do it like this:

y--;

console.log(x, y);

//with the ++ and == method you can only increase the value by one, and if you want to increase the
value more than one, you can do it like this:

x += 2;

y -= 4;

console.log(x, y); //you can even use the variable as the value, or maybe use /= or *=. Example:

x += y;

y *= x;

console.log (x); // the result will be x + y;

You might also like