Stuck on the buttons exercise

I’m learning Elm for the first time, and I’m stuck on the exercise part of the buttons guide.

Exercise: Add a button to reset the counter to zero:

  1. Add a Reset variant to the Msg type
  2. Add a Reset branch in the update function
  3. Add a button in the view function.

Here is the code I came up with.

https://ellie-app.com/g2J95WJRTZGa1

The error I’m seeing is as follows

 I was not expecting to see this equals sign:
 55|       model = 0
                 ^
Maybe you want == instead? To check if two values are equal?

I’m not sure how to finish this exercise.

Is = not for assignment? I wish the guide would show a completed example so I could see what I’m doing wrong.

Welcome to Elm!

One of the key attributes of Elm is immutability. You cannot change the value of a variable by assignment. Your update function just needs to return a new value of type Model. So in this case all you have to write in that branch is

0

as opposed to model = 0

You also seem to have an extra
Model →
in your type annotation for update, so once you change both of those things the Ellie will work.

2 Likes

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.