├── C-str └── README.md /C-str: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity 0.8.17; 3 | 4 | contract ControlStructures { 5 | // Define custom errors for use within the contract 6 | error AfterHours(uint256 time); 7 | error AtLunch(); 8 | 9 | // Function to determine the response based on the input number 10 | function fizzBuzz(uint256 _number) public pure returns (string memory response) { 11 | // Check if the number is divisible by both 3 and 5 12 | if (_number % 3 == 0 && _number % 5 == 0) { 13 | return "FizzBuzz"; // Return "FizzBuzz" if divisible by both 3 and 5 14 | } 15 | // Check if the number is divisible by 3 16 | else if (_number % 3 == 0) { 17 | return "Fizz"; // Return "Fizz" if divisible by 3 18 | } 19 | // Check if the number is divisible by 5 20 | else if (_number % 5 == 0) { 21 | return "Buzz"; // Return "Buzz" if divisible by 5 22 | } 23 | // If none of the above conditions are met 24 | else { 25 | return "Splat"; // Return "Splat" if none of the conditions are met 26 | } 27 | } 28 | 29 | // Function to determine the response based on the input time 30 | function doNotDisturb(uint256 _time) public pure returns (string memory result) { 31 | // Ensure the input time is within valid bounds (less than 2400) 32 | assert(_time < 2400); 33 | 34 | // Check different time ranges and return appropriate responses or revert with errors 35 | if (_time > 2200 || _time < 800) { 36 | revert AfterHours(_time); // Revert with custom error if it's after 10:00 PM or before 8:00 AM 37 | } 38 | else if (_time >= 1200 && _time <= 1299) { 39 | revert AtLunch(); // Revert with custom error if it's between 12:00 PM and 1:00 PM 40 | } 41 | else if (_time >= 800 && _time <= 1199) { 42 | return "Morning!"; // Return "Morning!" if it's between 8:00 AM and 11:59 AM 43 | } 44 | else if (_time >= 1300 && _time <= 1799) { 45 | return "Afternoon!"; // Return "Afternoon!" if it's between 1:00 PM and 5:59 PM 46 | } 47 | else if (_time >= 1800 && _time <= 2200) { 48 | return "Evening!"; // Return "Evening!" if it's between 6:00 PM and 10:00 PM 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Control-Structures --------------------------------------------------------------------------------