When I click the random button nothing happens
It is because you are ‘overwriting’ the value of the
state
variable.Initially you have it as a list:
state // state list Utah [state = "Utah", geo = "landlocked"] Arizona [state = "Arizona", geo = "landlocked"] Tennessee [state = "Tennessee", geo = "landlocked"] Alaska [state = "Alaska", geo = "coastal"] Florida [state = "Florida", geo = "coastal"]
But after loading the page, it would automatically ‘evaluate’ the
state
list on theoutput
in which it would evaluate to:[state] - random item from the `state` list -> Utah [state="Utah", geo = "landlock"] -> Utah landlock
With the
state = "Utah"
in the square brackets, you are overwriting thestate
list to just have the valueUtah
in which after you click the randomize button, instead of it using the initial list, it would only just outputUtah
since it is the value that was assigned to thestate
variable.So, the solution would be like this:
state Utah [geo = "landlocked", ''] Arizona [geo = "landlocked", ''] Tennessee [geo = "landlocked", ''] Alaska [geo = "coastal", ''] Florida [geo = "coastal", '']
This list would output the state and then set the
geo
variable to its value. In[geo = "landlocked", '']
, the, ''
is there to have the square brackets output nothing (or an empty string).Since all square brackets, after evaluating it, always output the result in the square bracket, like in
[
, the last thing to be evaluated is the ]geo = "landlock"
, therefore the engine would outputlandlock
on the page, so to prevent that we add an empty string at the end of the brackets.Thank you