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>

Answer

function add1() {
    alert("Adding +5 to your score!");
    score = score + 5;
    alert(score);

    };

Write a comment

Your email address will not be published. Required fields are marked *