Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding scores to a variable

I am new to coding and I have completed Codecademy's HTML, CSS and Javascript courses, and now I am making a very simple game.

I am trying to add 5 to my variable score, but I don't know how! I can use ++score to add 1, but I don't know how to add 5.

My simplified code for adding 1 is:

<html>
<head>
<title>Webpage</title>
<script>
var score = 0;
function add1() {
    alert("Adding +1 to your score!");
    ++score;
    alert(score);
    };
</script>
</head>
<body>
<button onclick="add1()";> Add One </button>
</body>
</html>
like image 905
user3672496 Avatar asked Mar 20 '23 12:03

user3672496


1 Answers

shortest / easiest + 5 in Javascript

 score += 5;
like image 93
VADEMO Avatar answered Mar 31 '23 16:03

VADEMO