What helped me to understand this, is that it seems really similar to when you create a class in JavaScript, and then use that class as a template to construct multiple object instances, thereby saving you having to write lots of repetitve code e.g.
class Person {
constructor(name, age) {
this.name = name;
this.age = age;
this.senior = age >= 65;
}
}
const personA = new Person('Bob', 36);
const personB = new Person('Alice', 68);
console.log(personA); // Person { name: 'Bob', age: 36, senior: false }
console.log(personB); // Person { name: 'Alice', age: 68, senior: true }
console.log(
`${personA.name} ${personA.senior ? 'is a senior' : 'isn\'t a senior'}`
);
// --> Bob isn't a senior
console.log(
`${personB.name} ${personB.senior ? 'is a senior' : 'isn\'t a senior'}`
);
// --> Alice is a senior
I do realise that classes aren’t covered in the JavaScript for Blockchain Developers course, and so some people may not be familiar with these; however, even though there are differences in syntax, would you agree that parallels can be drawn between how classes in JavaScript and structs in Solidity work?
Haha. We have all been there and done that… And we will all do it again and again…
So don’t worry, cuz nobody really cares, we are just glad It was you this time and not one of us.
what does the error message in remix say? the red x…
I’ll give u one clue. Indentation. Your error is not at line 23, it starts at line 14 i think.
I believe solidity needs the indentations to be correct to run. I might be wrong but it’s worth a try I think.
Hi @Mark1
Solidity doesn’t take the indentation in consideration, but indeed look at where you are openning your functions and where you are closing it.
You will see that a line 14 you are closing the function setMessage, using a better indentation will help you to see that you are not closing your contract bracket. This is your error.
OMG! Filip! This is awesome to have this utility “remix” to build smart contracts. It was in 2017 when I started reading about (blockchain) smart contracts (POW/POS). Now, I get my first opportunity to learn what its all about. Thanks Ivan on Tech Academy!
That’s right, In Remix we can open files form local storage, but not save to local storage, It’s strange I know… So my solution to just copy&paste the code into Atom editor.