Skip to content

Instantly share code, notes, and snippets.

@howardpen9
Created February 17, 2022 05:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save howardpen9/6d4c5568df4e43d7ada5b2a1ee78c388 to your computer and use it in GitHub Desktop.
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=
// 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