A variable is a name into which a value can be stored. There are several reasons for which we might want to do this. The first is when we want to keep track of a value that changes over time. Let's keep track of the number of times a button is clicked.
<button>
) that has been clicked 0 times in the static html. <button id="button">0</button>
click_count
click_count
by 1; and change the text of the button to the new value of click_count.click_count
. (You can get this value by selecting the "click_count" block from the Variables menu)Note that it will be a common pattern that you first set a variable in the "at the start" block and then modify it in at "when the element with id ... is clicked" block. This first setting of the variable is called "initialisation".
We are now going to use all the array blocks we have learned about. We're going to create a game where you roll dice and your goal is to not total more than 11.
<p>So far you have rolled:</p>
<ul id="list"></ul>
<button id="button_roll">Roll the dice</button>
<p>Total: <span id="total">0</span>. <span id="info">Keep playing!</span></p>
<button id="button_remove">Remove the last roll</button>
<button id="button_restart">Start again</button>
<span id="info">
<span id="info">
<span id="total">
<span id="total">
to the sum of the numbers in the "rolls" array.<span id="total">
to 0<li>
to the list and set the total. Instead, we are going to re-display the whole list from the array - you will see why in the next step<span id="info">
. For this project, you should provide the user with the ability to input earnings and expenses and see the totals
Here are some additional ideas of projects that can be accomplished with the current blocks (some newer blocks haven't been properly introduced yet) and might be suitable/adaptable as landing page enhancements. They all fit generally into the "add some button or event handlers that add or modify some html" category.