Learn Courses My Dashboard

Result of Lesson 12 (14 Days Challenge)


I’m on lesson 12 of the 14 Days Challenge. I didn’t get the result of 0 decreasing or increasing accordingly as the prompt. It stays 0 as I’m clicking it. I’m wondering if someone could take a look at my code. I’m attaching a screenshot here.

Thank you in advance!

It seems you are not calling the increase or decrease function anywhere. I sugest that after the VStack you add an if statement where if shouldDecrease is true you call the function shouldDecrease else call shouldIncrease.
Hope this helps

Hi Ellie,

You are kind of on the right track but as Noel is suggesting, your button code should be looking at the boolean and deciding which function to call.

Then in each of the functions add your test code to determine whether the boolean should be set to true or false. For example in the function increase()

func increase () {
    let randAmount = Int.random(in: 1...10)
    number += randAmount

    if number > 50 {
        shouldDecrease = true

A tip for future reference.

When you post code, rather than providing a screen shot, paste your View code in as text and format it as a code block by selecting the text you have pasted in and tapping the </> button in the compose message toolbar. It will look like the example above.

This enables us to copy the code and do some testing and point you in the right direction.