twostraws / Unwrap

Learn Swift interactively on your iPhone.
https://www.hackingwithswift.com
Other
2.3k stars 312 forks source link

Valid solution not accepted for counting 5s in an array #250

Closed fmad closed 8 months ago

fmad commented 10 months ago

The exercise that goes: "Write code that goes over this array, counting the number of times it contains the number 5, then printing that total", does not accept a simple valid solution:

Steps to reproduce

This code works but is not accepted:

let numbers = [1, 5, 2, 5, 3, 5]
var count=0
for i in numbers {
  if i == 5 {
    count += 1
  }
}
print(count)

Expected behavior

It should count as correct, not failed

Actual behavior

image

Environment

Harry-KNIGHT commented 10 months ago

It's totally normal this solution doesn't work

Swift does not accept var count=0, it will ask you to have this syntax var count = 0

For me your answer is not good.

fmad commented 8 months ago

Sorry, missed the comment as I've been busy moving houses.

image

Swift playgrounds seems to like it enough as you can see from above snapshot.

I'm not too fussed though, I realized by now that this program has a set fixed number of "good" answers and I'm done with the challenges anyway, so there's no point in keeping this open.