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
// SPDX-License-Identifier: MIT | |
pragma solidity ^0.8.9; | |
contract loopAndFunctionChallenge{ | |
// function that takes two number and add them together | |
function addTwoNumber(uint a, uint b) external pure returns (uint) { | |
return a + b; | |
} | |
// function that substract two given number | |
function substractTwoNumber(uint a, uint b) external pure returns (uint){ | |
//checking to make sure it does not return negative number |
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
// SPDX-License-Identifier: MIT | |
pragma solidity ^0.8.9; | |
contract IfElse { | |
function foo(uint x) public pure returns (uint) { | |
if (x < 10) { | |
return 0; | |
} else if (x < 20) { | |
return 1; | |
} else { |
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
// SPDX-License-Identifier: MIT | |
pragma solidity ^0.8.9; | |
contract EtherConverter { | |
uint256 public weiFactor = 10**18; // Conversion factor from ether to wei | |
uint256 public gweiFactor = 10**9; // Conversion factor from ether to gwei | |
function etherToWei(uint256 _etherValue) public view returns (uint256) { | |
return _etherValue * weiFactor; |
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
// SPDX-License-Identifier: MIT | |
pragma solidity ^0.8.18; | |
// FIRST CHALLENGE | |
// Write a simple contract and declare four different types of variables. | |
// Write get and set functions for each of these variables. | |
//Return the value of the variable in the “set function”. | |
contract ChallengeOne { |