Be Sociable, Share!

jueves, 12 de mayo de 2022

Mathematical Assignment Operators

 let w = 4;

w = w + 1;

console.log(w); // Output: 5


let x = 20;

x -= 5; // Can be written as x = x - 5

console.log(x); // Output: 15

 

let y = 50;

y *= 2; // Can be written as y = y * 2

console.log(y); // Output: 100

 

let z = 8;

z /= 2; // Can be written as z = z / 2

console.log(z); // Output: 4






let levelUp = 10;

let powerLevel = 9001;

let multiplyMe = 32;

let quarterMe = 1152;


// Use the mathematical assignments in the space below

// These console.log() statements below will help you check the values of the variables.

// You do not need to edit these statements. 

console.log('The value of levelUp:', levelUp); 

console.log('The value of powerLevel:', powerLevel); 

console.log('The value of multiplyMe:', multiplyMe); 

console.log('The value of quarterMe:', quarterMe);

levelUp+=5;

powerLevel-=100;

multiplyMe*=11;

quarterMe/=4;


Just like the previous mathematical assignment operators (+=-=*=/=), the variable’s value is updated and assigned as the new value of that variable. 


let gainedDollar = 3;

let lostDollar = 50;

gainedDollar++;

lostDollar--;


let myName = 'Natalia';

let myCity = 'Mexico City';

console.log(`My name is ${myName}. My favorite city is ${myCity}.`)


No hay comentarios:

Publicar un comentario