Get Programming with JavaScript - Listing 2.04
Listing 2.04 - Variables vary
JS Bin
var score;
score = 100;
console.log(score);
score = 150;
console.log(score);
Further Adventures
Listing 2.04 - Variables vary - Task 1
- Change the value assigned to score.
var score;
score = 500; // assign a new value here
console.log(score);
score = 15; // and/or assign a new value here
console.log(score);
score = 0.5; // and/or assign a new value here
Listing 2.04 - Variables vary - Tasks 2, 3 and 4
- Declare a second variable, maybe score2.
- Assign your variable a value.
- Use console.log to display your variable on the console.
var score;
score = 100;
console.log(score);
score = 150;
console.log(score);
var score2; // declare a new variable
score2 = 0.5; // assign it a value
console.log(score2); // display the new variable
Listing 2.04 - Variables vary - Tasks 5 and 6
- Add a new line of code to alter the value of your variable after it has been displayed on the console.
- Add a new line of code to display the new value of your variable.
var score;
score = 100;
console.log(score);
score = 150;
console.log(score);
var score2;
score2 = 0.5;
console.log(score2);
score2 = 99; // assign a new value
console.log(score2); // display the new value