Lesson 11 challenge add and multiply button

Hello, I have successfully completed the challenge.
Texfield display when I press add or multiply button, but only twice.
I can add and than multiply it and than add to that and than multiply it, but i can not add to added, if you know what I mean, what do you think?
I feel i should put there conditional or something.

Thank you xxxx

Hi Ewa,

Can you paste the entire contents of your code in ContentView.swift in a reply.

To format your code nicely in your reply put 3 back-ticks ``` as the first characters on a new line and then paste your code, then place 3 back-ticks on a new line after your code.

1 Like

maybe you didn’t get the current value of the textfield as “base”
like you saved the current value as a variable and forgot to update it after the computation

1 Like

Dear Chris just had coffee and solved it , too many variables for nor reason, I show you the outcome anyways:) glad to solve own stuff :slight_smile:

struct ContentView: View {
    
   @State private var num = 0
   //@State private var multiply = 0
   @State private var score = "0"
    
    var body: some View {
        
        VStack{
            Text(score)
            HStack{
                Button(action: {
                    
            num += 2
            score = (String(num))
                    
                }, label: {
                    /*@START_MENU_TOKEN@*/Text("Button")/*@END_MENU_TOKEN@*/
                })
                Button(action: {
                    num = num  * 2
                    score = (String(num))
                }, label: {
                    /*@START_MENU_TOKEN@*/Text("Button")/*@END_MENU_TOKEN@*/
                })
                
            }
            
            
        }
    }
}

Im new I dont know what base is, but thank you, send me a link to lesson about it if you have time, have a lovely day :slight_smile:

Well done. It’s always satisfying to solve the problem yourself.

1 Like

Hi,

I solved the challenge and want to check ,my result with you.

Here you go,
//
// ContentView.swift
// lesson11-challenge
//
// Created by Mohamad Al Sabban on 2/11/21.
//

import SwiftUI

struct ContentView: View {

@State var num = 0

var body: some View {
   
    VStack {
        Text(String(num))
            .font(.largeTitle)
        Button(action: {
            
            num = num + 2
            
            
            
        }, label: {
            /*@START_MENU_TOKEN@*/Text("Button")/*@END_MENU_TOKEN@*/
        })
        Button(action: {
            
            num = num * 2
        }, label: {
            /*@START_MENU_TOKEN@*/Text("Button")/*@END_MENU_TOKEN@*/
        })
    }

    
    
}

}

Please let me know how I did.