From f24004cb910a409eca7b84d92c0ad0f102e98b20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nikolai=20Lillemark=20B=C3=B8rseth?= Date: Tue, 7 Jan 2025 15:02:48 +0100 Subject: [PATCH] Yes... --- csharp-fundamentals-control-flow.Main/Core.cs | 39 ++++++++++++------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/csharp-fundamentals-control-flow.Main/Core.cs b/csharp-fundamentals-control-flow.Main/Core.cs index 9fe1a9d..9f5e532 100644 --- a/csharp-fundamentals-control-flow.Main/Core.cs +++ b/csharp-fundamentals-control-flow.Main/Core.cs @@ -48,61 +48,61 @@ public string sayGoodMorning(bool isMorning) // Change the returned value in the method below to your answer. It is case-sensitive. public string one() { - return ""; + return "Good day!"; } //TODO: 2. What will the output be if I run sayGoodMorning(true)? // Change the returned value in the method below to your answer. It is case-sensitive. public string two() { - return ""; + return "Good morning!"; } //TODO: 3. What will the output be if I run sayGoodMorning("Hello" == "Hello")? // Change the returned value in the method below to your answer. It is case-sensitive. public string three() { - return ""; + return "Good morning!"; } //TODO: 4. What will the output be if I run sayGoodMorning("A word" != "Another word") public string four() { - return ""; + return "Good morning!"; } // 5. What will the output be if I run sayGoodMorning(25 != 25) public string five() { - return ""; + return "Good day!"; } //TODO: 6. Use a conditional statement to return "Correct!" if the input is more than 7 // or "Wrong!" if not public string six(int num) { - throw new NotImplementedException(); + return num > 7 ? "Correct!" : "Wrong!"; } //TODO: 7. Use a conditional statement to return "Correct!" if the input is false // or "Wrong!" if not public string seven(bool boolean) { - throw new NotImplementedException(); + return !boolean ? "Correct!" : "Wrong!"; } //TODO: 8. Use a conditional statement to return "Correct!" if numOne is more than or equal to numTwo // or "Wrong!" if not public string eight(int numOne, int numTwo) { - throw new NotImplementedException(); + return numOne >= numTwo ? "Correct!" : "Wrong!"; } //TODO: 9. Use a conditional statement to return true if the array provided is not empty // or false if it is empty public bool nine(int[] nums) { - throw new NotImplementedException(); + return nums.Length != 0; } //TODO: 10. Use a conditional statement to return true if the provided string contains the word @@ -110,7 +110,7 @@ public bool nine(int[] nums) // https://www.w3schools.com/java/java_ref_string.asp public bool ten(string sentence) { - throw new NotImplementedException(); + return sentence.Contains("milk"); } //TODO: 11. Use conditional statements to return the number 3 if the provided string contains @@ -119,14 +119,17 @@ public bool ten(string sentence) // Otherwise, return the number 0. public int eleven(string sentence) { - throw new NotImplementedException(); + int count = 0; + if (sentence.Contains("milk")) { count += 3; } + if (sentence.Contains("coffee")) { count += 6; } + return count; } //TODO: 12. Use conditional statements to return true if num is more than or equal to lower and is // less than or equal to upper, otherwise return false. public bool twelve(int num, int lower, int upper) { - throw new NotImplementedException(); + return lower <= num & num <= upper; } /* @@ -141,7 +144,17 @@ public bool twelve(int num, int lower, int upper) */ public string thirteen(int age) { - throw new NotImplementedException(); + switch (age) { + case 0: + return "Baby"; + case int i when i >= 1 & i <= 4: + return "Toddler"; + case int i when i >= 5 & i <= 12: + return "Child"; + case int i when i >= 13 & i <= 19: + return "Teenager"; + default: return "Adult"; + } } } }