Hi Filip!
in the video arrays and structs
I think there is a “bug” in your code. I didnt get why you put the -1
at the end of line 13, so i just skipped it and my contract worked just fine. Then i check also arbitrary values and figured out that this last statement doesnt affect the returned id
at all. So for example when i put 12
it still works for me, see code below:
pragma solidity 0.5.1;
contract DogContract {
struct Dog {
string name;
uint age;
}
Dog[] dogs;
function addDog(string memory _name, uint _age) public returns (uint) {
return dogs.push(Dog(_name, _age)) -12;
}
function getDogsName(uint _id) public view returns (string memory) {
return dogs[_id].name;
}
}
So the returned uint
is not used anywhere in the code. So leaving out the whole return statement also works fine for me (i still can use the getDogsName
function properly!):
function addDog(string memory _name, uint _age) public {
dogs.push(Dog(_name, _age));
}
EDIT: just watched the next episode, and there you also deleted the return value, so i guess it was not necessary, right? One final question i have: is there a console log i can use to check some values? For example how can i print something to the console to see the value of it?