-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path2-Control Structures.sol
More file actions
36 lines (32 loc) · 1.03 KB
/
2-Control Structures.sol
File metadata and controls
36 lines (32 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
contract ControlStructures {
error AfterHours(uint time);
function fizzBuzz(uint _number) public pure returns (string memory) {
if (_number % 3 == 0 && _number % 5 == 0) {
return "FizzBuzz";
} else if (_number % 3 == 0) {
return "Fizz";
} else if (_number % 5 == 0) {
return "Buzz";
} else {
return "Splat";
}
}
function doNotDisturb(uint _time) public pure returns (string memory) {
assert(_time < 2400);
if (_time > 2200 || _time < 800) {
revert AfterHours(_time);
} else if (_time >= 1200 && _time <= 1259) {
revert("At lunch!");
} else if (_time >= 800 && _time <= 1199) {
return "Morning!";
} else if (_time >= 1300 && _time <= 1799) {
return "Afternoon!";
} else if (_time >= 1800 && _time <= 2200) {
return "Evening!";
} else {
return "";
}
}
}