Get Programming with JavaScript - Listing 2.08
Listing 2.08 - Using a variable’s current value to set its new value
JS Bin
var score;
score = 100;
console.log("Your score was " + score);
console.log("Great splat!!!");
score = score + 50;
console.log("New score: " + score);
console.log("Way to go!");
Further Adventures
Listing 2.08 - Using a variable’s current value to set its new value - Task 1
- Tell the player of a successful splat
var score;
score = 100;
console.log("Your score was " + score);
console.log("Great splat!!!");
score = score + 50;
console.log("New score: " + score);
console.log("Way to go!");
console.log("Great splat!!!"); // successful splat
Listing 2.08 - Using a variable’s current value to set its new value - Task 2
- Add 100 to the player's score
var score;
score = 100;
console.log("Your score was " + score);
console.log("Great splat!!!");
score = score + 50;
console.log("New score: " + score);
console.log("Way to go!");
console.log("Great splat!!!");
score = score + 100; // add 100
Listing 2.08 - Using a variable’s current value to set its new value - Task 3
var score;
score = 100;
console.log("Your score was " + score);
console.log("Great splat!!!");
score = score + 50;
console.log("New score: " + score);
console.log("Way to go!");
console.log("Great splat!!!");
score = score + 100;
console.log("New score: " + score); // show the new score
Listing 2.08 - Using a variable’s current value to set its new value - Task 4
- Display a message of congratulations
var score;
score = 100;
console.log("Your score was " + score);
console.log("Great splat!!!");
score = score + 50;
console.log("New score: " + score);
console.log("Way to go!");
console.log("Great splat!!!");
score = score + 100;
console.log("New score: " + score);
console.log("Awesome! You're the best."); // display a message
Video Tutorials
Using a variable's current value to set its new value