Post
Share your knowledge.
can't understand what are the locations(uint256)
I don't understand what are the uint256 of Location, and newLocation, can someone explain to me, where are they? Thank you. Below is the code:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.18;
import {AFoundryCourseChallenge} from "AFoundryCourseChallenge.sol"; import {LessonThreeHelper} from "3-LessonHelper.sol";
contract LessonThree is AFoundryCourseChallenge, LessonThreeHelper { error LessonThree__WrongLocation();
string private constant LESSON_IMAGE = "ipfs://QmfWyPRrx1sx7sfgrwr4pNMWtqVLXMwCP4fej39m2fPfYe";
constructor(address fcn) AFoundryCourseChallenge(fcn) {
s_booleanArray = [false, false, false, true, false];
}
/*
* CALL THIS FUNCTION!
*
* @param location - The location of the true boolean.
* @param newLocation - Pick the spot of the boolean for the next person!
* @param yourTwitterHandle - Your twitter handle. Can be a blank string.
*/
function solveChallenge(uint256 location, uint256 newLocation, string memory yourTwitterHandle) external {
if (s_booleanArray[location] != true) {
revert LessonThree__WrongLocation();
}
s_booleanArray[location] = false;
s_booleanArray[newLocation] = true;
_updateAndRewardSolver(yourTwitterHandle);
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////// The following are functions needed for the NFT, feel free to ignore. ///////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////
function description() external pure override returns (string memory) {
return "Cyfrin Foundry Full Course: You've inherited skillz from solidity!";
}
function attribute() external pure override returns (string memory) {
return "Inheritance and factory pattern knowledgable";
}
function specialImage() external pure override returns (string memory) {
return LESSON_IMAGE;
}
}
- Smart Contract
- Solidity
Answers
2Without knowledge of the full context, it is hard to explain from this challenge's perspective.
Speaking of the code, location
is an index of an item in s_booleanArray
array where the value is true
. If the value of an element by index location
is true
then solveChallenge
sets it to false
, and sets to true
an item by index newLocation
.
The uint256 location and uint256 newLocation parameters in the solveChallenge function represent the indices of the array s_booleanArray.
s_booleanArray is an array of boolean values initialized with [false, false, false, true, false]. This means that the true value is at the 4th index in the array (considering that array indices start at 0). The solveChallenge function takes in two arguments location and newLocation, representing the index of the array s_booleanArray. The location parameter should be the index of the true value in the s_booleanArray. If the value at s_booleanArray[location] is not true, it reverts the transaction using revert LessonThree__WrongLocation. If s_booleanArray[location] is true, it sets this index to false and the newLocation index to true. This effectively moves the true value to a new location in the array. Finally, it calls _updateAndRewardSolver(yourTwitterHandle); to update the solver's status and reward them. So, if you are trying to solve this challenge, you would need to provide the current location of the true value (which starts at index 3, based on the array initialization), and a new location where you want to move the true value to.
That's all I can tell from the information you've given.
Do you know the answer?
Please log in and share it.
Solidity is an object-oriented, high-level language for implementing smart contracts. It is a curly-bracket language designed to target the Ethereum Virtual Machine (EVM).
- My ERC721 contract successfully deploys, but I can't verify the contract's source code with hardhat21
- Solidity and ethers.js Compute Different Addresses from the Same Signature21
- can't understand what are the locations(uint256)22
- How to reverse keccak256 in solidity22
- Clarification on Gas Refunds and Comparison Between "require" and "revert" in Smart Contracts21