UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

100 days of SwiftUI

Forums > Swift

Hi HWS forum,

I am doing the HWS 100 days course (which I really enjoy).

I am currently on - Day 7: I am taking the returning values test and do not understand question 10.

I wrote it out in a playground, and do not know what to write in order to print true or false.

if I write the following after the func "let answer = allTestsOassed(test: true) print(answer)" I get errors. Here is the screenshot. https://gyazo.com/0be28589d962af182381e2fcd10506e1

Thanks, Jce

2      

try this

func forallTestspassed(tests: [Bool]) -> Bool {
    for test in tests {
        if test == false {
            return false
        }
    }
    return true
}

let answer = forallTestspassed(tests: [true, false, true])
print(answer)

You need an array of boolean values as that is what is expected from function func forallTestspassed(tests: [Bool])

the second error is just a typo of test

But the point of interest is also the return statement, the moment the codition of test == false is satisfied the control will move to the calling site and prints the result , this will not iterate through all values and prints true or false checking each value, because of nature of return statement ...

2      

BUILD THE ULTIMATE PORTFOLIO APP Most Swift tutorials help you solve one specific problem, but in my Ultimate Portfolio App series I show you how to get all the best practices into a single app: architecture, testing, performance, accessibility, localization, project organization, and so much more, all while building a SwiftUI app that works on iOS, macOS and watchOS.

Get it on Hacking with Swift+

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.