Skip to content

Commit

Permalink
Conditionals and loops
Browse files Browse the repository at this point in the history
Signed-off-by: George J Padayatti <[email protected]>
  • Loading branch information
georgepadayatti committed Jul 7, 2022
1 parent 7b65495 commit 219e03f
Showing 1 changed file with 25 additions and 27 deletions.
52 changes: 25 additions & 27 deletions contracts/DEXA.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,39 +12,37 @@ pragma solidity ^0.8.0;
*/

contract DEXA {
// Mappings
mapping(uint256 => string) public names;
mapping(uint256 => Book) public books;
mapping(address => mapping(uint256 => Book)) public mybooks;

struct Book {
string title;
string author;
}
// Conditionals and Loops

uint256[] public numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];

address public owner;

constructor() {
names[1] = "Adam";
names[2] = "Bruce";
names[3] = "Carl";
owner = msg.sender;
}

function addBook(
uint256 _id,
string memory _title,
string memory _author
) public {
// Local variables are prefixed with "_" (Underscore) as part of convention
books[_id] = Book(_title, _author);
function isOwner() public view returns (bool) {
return (msg.sender == owner);
}

function addMyBook(
uint256 _id,
string memory _title,
string memory _author
) public {
// Global variables
// msg.sender -> Address of the individual who is calling the smartcontract function.
function countEvenNumbers() public view returns (uint256) {
uint256 count = 0;

for (uint256 i = 0; i < numbers.length; i++) {
if (isEvenNumber(numbers[i])) {
count++;
}
}

return count;
}

mybooks[msg.sender][_id] = Book(_title, _author);
function isEvenNumber(uint256 _number) public pure returns (bool) {
if (_number % 2 == 0) {
return true;
} else {
return false;
}
}
}

0 comments on commit 219e03f

Please sign in to comment.