newbie needs help with basic function exercise

I am working my way through a Swift course from 2015. It is asking me to "Write a function called magicEightBall that generates a random number and then uses either a switch statement or if-else-if statements to print different responses based on the random number generated. let randomNum = Int.random(in: 0...4) will generate a random number from 0 to 4, after which you can print different phrases corresponding to the number generated. Call the function multiple times and observe the different printouts."

Here is what I have written so far, but it isn't working:

func magicEightBall(randomNum: Int) {

    let randomNum = Int.random(in: 0...4)

    

    print(randomNum)

}



magicEightBall()

I keep getting an error that says "Missing argument for parameter 'randomNum' in call

any help would be greatly appreciated, Thank You
Your code redefines a randomNum and does not use the parameter you pass.
To work, you should pass a parameter:
magicEightBall(randomNum: 100)
But this value is not used in the func, because you redefine randomNum.

You just don't need this parameter.

Just write:
Code Block
func magicEightBall() {
let randomNum = Int.random(in: 0...4)
print(randomNum)
}
magicEightBall()

If you need to use the generated random, return it from the func.
Here is code in playground:

Code Block
func magicEightBall() -> Int {
let randomNum = Int.random(in: 0...4)
return randomNum
}
let randomValue = magicEightBall()
switch randomValue {
case 0 : print("You scored Zero: retry")
case 1 : print("You scored One: good start")
case 2 : print("You scored Two: improving")
case 3 : print("You scored Three: you're nearly there")
case 4 : print("You scored Four: bingo")
default: break
}

Good continuation and don't forget to close the thread on this answer if that's OK.
newbie needs help with basic function exercise
 
 
Q