Last active
February 5, 2025 06:09
-
-
Save TheMuellenator/f290a658bfd19773dadacffc8000498e to your computer and use it in GitHub Desktop.
iOS repl.it - Optionals Challenge Solution
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Don't change this | |
var studentsAndScores = ["Amy": Int(readLine()!)!, "James": Int(readLine()!)!, "Helen": Int(readLine()!)!] | |
func highestScore(scores: [String: Int]) { | |
//Write your code here. | |
let a = studentsAndScores["Amy"]! | |
let b = studentsAndScores["James"]! | |
let c = studentsAndScores["Helen"]! | |
var temp = 0 | |
//If a is greater than b | |
if a > temp { | |
//And a is also greater than c | |
temp = a | |
} | |
if b > temp { | |
temp = b | |
} | |
if c > temp { | |
temp = c | |
} | |
print(temp) | |
} | |
//Don't change this | |
highestScore(scores: studentsAndScores) |
This is my solution :
//Don't change this
var studentsAndScores = ["Amy": Int(readLine()!)!, "James": Int(readLine()!)!, "Helen": Int(readLine()!)!]
func highestScore(scores: [String: Int]) {
let amyScore = scores["Amy"]!
let jamesScore = scores["James"]!
let helenScore = scores["Helen"]!
// Find the highest score
let maxScore = max(amyScore, jamesScore, helenScore)
// Print only the highest score
print(maxScore)
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
let studentsAndScores: [String: Int] = [:]
func highestScore(scores: [String: Int]) {
print(scores.values.max() ?? "Damn")
}
highestScore(scores: studentsAndScores)