# Bull's Eye Tutorial - Score is not adding correctly

**URL:** <https://forums.kodeco.com/t/bulls-eye-tutorial-score-is-not-adding-correctly/56645>\
**Category:** Swift\
**Created:** [November 30, 2018, 2:25am UTC](https://forums.kodeco.com/t/bulls-eye-tutorial-score-is-not-adding-correctly/56645 "2018-11-30T02:25:17Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![hunterfitch](https://s3.amazonaws.com/cdn.raywenderlich.com/community/forum-assets/noun-game-ghost-878668.png) [@hunterfitch](https://forums.kodeco.com/u/hunterfitch)\
**Post date:** [November 30, 2018, 2:25am UTC](https://forums.kodeco.com/t/bulls-eye-tutorial-score-is-not-adding-correctly/56645/1 "2018-11-30T02:25:17Z")

</div>

Hello there! I’ve just completed the portion of the Bull’s Eye tutorial where we’ve added 100 additional points for a perfect score and 50 points for a 99… the score on the alert menu is correct. For instance if I get a perfect score it tells me I’ve earned 200 points but that is not actually translating into the overall score, it’s still only adding on 100 points. Same if I hit 99… it says I’ve earned 149 points in the alert menu but only tallies 99 points to my score. Thank you in advance!

---

<div class="post-metadata">

**Author:** ![jayantvarma](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/jayantvarma/32/111768_2.png) [@jayantvarma](https://forums.kodeco.com/u/jayantvarma)\
**Post date:** [November 30, 2018, 4:40am UTC](https://forums.kodeco.com/t/bulls-eye-tutorial-score-is-not-adding-correctly/56645/2 "2018-11-30T04:40:34Z")

</div>

hi @hunterfitch,  
It seems that your score is being added twice, if you post the code - you can get some suggestions on where and how to fix it.

cheers,

---

<div class="post-metadata">

**Author:** ![hunterfitch](https://s3.amazonaws.com/cdn.raywenderlich.com/community/forum-assets/noun-game-ghost-878668.png) [@hunterfitch](https://forums.kodeco.com/u/hunterfitch)\
**Post date:** [November 30, 2018, 2:17pm UTC](https://forums.kodeco.com/t/bulls-eye-tutorial-score-is-not-adding-correctly/56645/3 "2018-11-30T14:17:09Z")

</div>

import UIKit

class ViewController: UIViewController {

```
@IBOutlet weak var slider: UISlider!
@IBOutlet weak var targetLabel: UILabel!
@IBOutlet weak var scoreTotal: UILabel!
@IBOutlet weak var roundLabel: UILabel!

var currentValue = 0
var targetValue = 0
var score = 0
var round = 0

override func viewDidLoad() {
    super.viewDidLoad()
    
    let roundedValue = slider.value.rounded()
    currentValue = Int(roundedValue)
    startOverButton()
}

@IBAction func showAlert(_ sender: Any) {
    
    let difference = abs(currentValue - targetValue)
    var points = 100 - difference
    
    score += points
    
    let title: String
    if difference == 0 {
        title = "Perfect! 100 Bonus Points!"
        points += 100
    } else if difference < 5 {
        title = "You Almost Had It!"
        if difference == 1 {
            points += 50
        }
    } else if difference < 10 {
        title = "Pretty Good!"
    } else {
        title = "Not Even Close!"
    }
    
    let message = "You Scored \(points) Points"
    
    let alert = UIAlertController(title: title, message: message, preferredStyle: .alert)
    
    let action = UIAlertAction(title: "OK", style: .default, handler: {
        action in
        self.startNewRound()
    })
    
    alert.addAction(action)
    
    present(alert, animated: true, completion: nil)
    
}

@IBAction func sliderMoved(_ slider: UISlider) {
    
    let roundedValue = slider.value.rounded()
    currentValue = Int(roundedValue)
}

func startNewRound() {
    round += 1
    targetValue = Int.random(in: 1 ... 100)
    currentValue = 50
    slider.value = Float(currentValue)
    updateLabels()
}

func updateLabels() {
    targetLabel.text = String(targetValue)
    scoreTotal.text = String(score)
    roundLabel.text = String(round)
}

@IBAction func startOverButton() {
    score = 0
    round = 0
    startNewRound()
}

```

}

---

<div class="post-metadata">

**Author:** ![anon64978853](https://s3.amazonaws.com/cdn.raywenderlich.com/community/forum-assets/noun-game-ghost-878668.png) [@anon64978853](https://forums.kodeco.com/u/anon64978853)\
**Post date:** [November 30, 2018, 3:13pm UTC](https://forums.kodeco.com/t/bulls-eye-tutorial-score-is-not-adding-correctly/56645/4 "2018-11-30T15:13:16Z")

</div>

You’ll have to put :

> score += points

Below :

> …  
> } else {  
> title = “Not Even Close!”  
> }
> 
> score += points // Here

The title/message would get set for your alert, but score itself only gets the bare points added, without the extra points ( before the block that conditionally assigns extra points ) :]

Putting that line after the extra points block should result into a correct score as well, including the extra points.

Grts,

---

<div class="post-metadata">

**Author:** ![hunterfitch](https://s3.amazonaws.com/cdn.raywenderlich.com/community/forum-assets/noun-game-ghost-878668.png) [@hunterfitch](https://forums.kodeco.com/u/hunterfitch)\
**Post date:** [November 30, 2018, 4:25pm UTC](https://forums.kodeco.com/t/bulls-eye-tutorial-score-is-not-adding-correctly/56645/5 "2018-11-30T16:25:47Z")

</div>

Thank you! That worked and it makes sense!

---

<div class="post-metadata">

**Author:** ![system](https://s3.amazonaws.com/cdn.raywenderlich.com/community/forum-assets/noun-game-ghost-878668.png) [@system](https://forums.kodeco.com/u/system)\
**Post date:** [May 15, 2019, 6:36pm UTC](https://forums.kodeco.com/t/bulls-eye-tutorial-score-is-not-adding-correctly/56645/6 "2019-05-15T18:36:38Z")

</div>

This topic was automatically closed after 166 days. New replies are no longer allowed.
