Variables in JavaScript
(Edited)
Today I learned the introduction to variables in JavaScript:
https://www.learn-js.org/en/Variables_and_Types
The exercise was to write the following variables:
A number called myNumber which contains the number 4
;
A string called myString which contains the sentence Variables are great.
;
A boolean called myBoolean which contains the value false
;
It was much harder than yesterday to write "Hello, World!"
. But finally I came up with this code:
1 var myNumber=4;
2 var myString="Variables are great.";
3 var myBoolean=false;
4 console.log("myNumber is equal to " + myNumber);
5 console.log("myString is equal to " + myString);
6 console.log("myBoolean is equal to " + myBoolean);
Did I write it correctly?
PS I didn't know how to do single spaced code in Markdown. Any suggestions?
0
0
0.000
Dear STEM Geek! I am writing this comment to inform you that the leader of our tribe, @themarkymark, has unfairly banned me from the discord server of our tribe. Show him we are a decentralized community and that such acts of tyranny will not be accepted in the STEM tribe! Tell him to let me in again!
Thank you!
P.S: Use the triple ` to embed code
Very good. Perhaps not include the line numbers in your code sharing though.
Here's a test for you...how do you swap the contents of these two variables?
Maybe this way?
Posted using Partiko Android
'a' and 'b' could contain anything, so we can't just assign a = 2, b = 1. Also in your answer, you have declared the variable name 'myNumber' twice. I don't think that is permitted in that context.
Here's the solution:
Does that make sense?
I see... It's above my pay-grade, haha! Tomorrow I will pick up a book JavaScript for Kids I ordered from Amazon. Do you prefer to study from books or from online sources?
I study by driving head on into the problem!
Posted using Partiko iOS
Does it hurt? Haha!
Posted using Partiko Android
I see... no numbering in code sharing?
Posted using Partiko Android
I think so. Because if someone copies and pastes the code snippet, they will have to remove the line numbers to get it to work.
Thanks for the tip again! I'm sorry I can't return the favor by teaching you anything new... You know everything I know...
That’s not true! You are the master of organ improvisation! I wish I could improvise even basic things 😢
Posted using Partiko iOS