Created
February 17, 2022 05:29
-
-
Save howardpen9/6d4c5568df4e43d7ada5b2a1ee78c388 to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.7.6+commit.7338295f.js&optimize=false&runs=200&gist=
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.7.1; | |
contract StudentScore { | |
mapping (string => uint) scores; | |
string[] names; | |
function addScore(string memory name, uint256 score) public { | |
scores[name] = score; // mapping declare | |
names.push(name); | |
} | |
function getScore(string memory name) public view returns (uint256) { | |
return scores[name]; | |
} | |
function deleteScore() public { | |
while (names.length >0 ) { | |
delete scores[names[names.length-1]]; // delete the name which is the last of the names Array. | |
names.pop(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment