If you're a novice programmer, the first thing you should realize is that languages aren't important, concepts are. I know enough to make me dangerous. You will be regurgitating "print" (ehrmm I mean console.log() ) statements in no time. You will likely hate it, until you don't. If you stick with me until the end of this thing we will learn how to build a bot for Hive together.
Everyone knows that computers speak in 1's and 0's. If you wrote everything in the language that the computer understands, you would probably want to jump off a bridge in a very short time. Fortunately, JS allows us the ability to create a human readable(ish) form that only mildly kills your willpower to live (functionally dead on the inside). You will get through this with sheer determination to one day too create a mega successful crypto "rug-pull" exit scam. After which you can follow the natural programmer progression and become a YouTuber. As this series continues I'll speak a little more about everything.
I am going to suggest that you go here. Just delete all of the text inside and try out the stuff below. Whenever you are ready to run your code click "run".
The first thing to understand is we need to break up our code into chunks that the interpreter can communicate in the computer's language. Consider it grammar for the computer. We need to tell the computer what to do with the code we are writing. Many times we need to preface our code with a declaration. There are many declarations you can use, but let's start with a constant or "const". A constant is an immutable number, much like the data you store here on hive. We'll call ours "immutableNumber". We write this way as it is the normal convention for naming stuff. Notice also in the code below that we end our "sentence" with a semicolon or ";".
const immutableNumber = 1;
Let's break this down:
"const" is a declaration that means constant. The computer now knows that we want this line to be a constant.
"immutableNumber" is just the name of our constant. We used a special coding convention so we match other people and can easily understand each other.
"= 1" means we are assigning the value of "immutableNumber" to equal 1.
Finally ";" is just the period at the end of our sentence. The computer now knows that we are done with our "sentence" or assignment.
So cool, we have written a line of code. If you run it on replit what happens? Absolutely nothing. Technically, we are only assigning a value to a place in the memory of the computer. The name "immutableNumber" is just a human readable version of a place where that value is assigned. Something really important to get across is that "=" does not mean equals. It's not like algebra or something. You are literally saying, "hey computer, call that spot in the memory 'immutableNumber' and let it hold the number (integer) 1 for me.
To be able to see what we just wrote, we need to use a special piece of code that displays information to the console. We can do that with this:
Anything that we write inside the parentheses of the function above will display the value assigned to it.
If we assign a constant with text, we can display that to the console. I'll use the infamous "Hello World" as an example below:
const helloWorld = "Hello World";
We just assigned the place in the memory called "helloWorld" words (or strings) the value of "Hello World".
If i use the below statement, the console will "print" "Hello World".
The final thing we'll learn about today is a comment. Comments are used to write yourself or other programmers notes about what your code is doing. This can be helpful when you're working on things that seem very complicated. If I use a "//" in front of a sentence I write, the interpreter ignores the line of code.
//This is a comment
This is all a lot to take in, and trust me, it gets much much worse. Do you want to be a big fancy Web3 developer or not? Let's stop here for today and pick up again later.
What happens when you reassign "evilPlans" with a new value in the same program?
Code your answers and use "```" before and after your code to share the results in the comments section below. If something doesn't work out as planned share your thoughts in the comments.
As always, if I did a really bad job explaining things, feel free to reach out and ask for help. I really don't mind.