SimpleStoragestoredNumber initialized to 0getNumber that returns the value of storedNumberSimpleStoragestoredNumber initialized to 0getNumber that returns the value of storedNumberSimpleStorage and declare a public unsigned integer variable called storedNumber initialized to 0.Start with contract SimpleStorage { } and inside it declare uint public storedNumber = 0;
SimpleStorage contract, write a public view function called getNumber that returns a uint and returns the value of storedNumber.Define function getNumber() public view returns (uint) { return storedNumber; } inside the contract.
setNumber that takes a uint parameter named newNumber and updates storedNumber with it.Write function setNumber(uint newNumber) public { storedNumber = newNumber; } inside the contract.
getNumber() after deploying the contract and before calling setNumber. The output should be 0.Write a comment like // Expected output of getNumber() after deployment: 0 below the contract.
What is the correct way to start defining a contract named SimpleStorage in Solidity?
contract followed by the contract name and curly braces.contract SimpleStorage { }, which is the correct syntax to start a contract.Which of the following is the correct syntax to declare a state variable count of type uint inside a contract?
uint count;. uint count = 0 misses the semicolon. Options B and D use incorrect syntax.What will be the output of the following Solidity function when called?
contract Test {
uint number = 5;
function getNumber() public view returns (uint) {
return number + 3;
}
}number is set to 5. The function returns number + 3.Identify the error in the following Solidity contract snippet:
contract Counter {
uint count
function increment() public {
count += 1;
}
}uint count is missing a semicolon at the end, which is required in Solidity.public is valid. Variables are correctly declared outside functions. Contract names can be uppercase.You want to create a contract that stores a person's name and age, and has a function to update the age. Which of the following contract structures correctly implements this?
contract Person {
string name;
uint age;
function setAge(uint newAge) public {
age = newAge;
}
}name and age are declared at contract level, which is correct for storing data.setAge takes a parameter and assigns it to age, correctly updating the state variable.Pass the test and this pattern moves unknown