coding help
FYI: This code doesn't work in the comments.
It also won't work in your sandbox or talk page.
To test your code, please go to your common.js.


Work In Progress
This page is a work in progress.


Introduction

JavaScript (JS) is a frontend/full-stack programming language used along side with HTML and CSS. JavaScript is usually used for calculations and other not visible stuff behind the scenes [change wording later; is not a scripting language]. JS is similar to many backend programming languages like Java or C (++/#), but it can be used to manipulate the web content (HTML).
It is recommended that you open a new tab and go to your common.js or get an account on Replit (external) so you can follow along.

Variables

A JavaScript variable is a memory location that can be used to store values. Some types of values that can be stored in JS are numbers, words, characters, arrays etc. Variables have to be declared so it exists, and initialized to have a particular value assigned to it.

The best way to explain is through examples, so let's go through a few!

let x = 3;


The code above declares and initializes a variable with a name x and value of 3. The keyword let is used to indicate that you are creating (declaring) a new variable, var can also be used but it is discouraged as it does not require strict programming syntax and could cause potential errors (which would be harder to find). DON'T FORGET THE SEMICOLON(;) AT THE END OF EACH LINE!!

Displaying the Results

Sometimes we want to actually see our result. One way we can we that is using something called "print". If you learned other programming languages, you probably already know what I'm talking about. Basically it can print something to the console for output. In JavaScript, we use console.log(); to print something to the console.

console.log("Hello World!");


The code above would produce the following result to the console:

Hello World!


Let's put both variables and the print function together now. Can you predict what the output will be for the following code?

let apple = 6;
let banana = 8;
let sum = apple + banana;
console.log(sum);


[explaination]

Data Types

Data types are the type of data stored in a particular variable. In JavaScript, you don't state which data type the variable is, but that means when you use them you'll have to be extra careful.

Integer

Double/Float

Boolean

Character

String

Functions

A function in JavaScriptis just like in math, but much simpler actually (I haven't learned functions yet so idk lol). A function simply means that whatever code you write inside that function is reusable without having to type the same lines of code every time you want to use it.
For example, here I have the same block of code from earlier.


Displaying to Webpage

To display something to an actual HTML webpage, you can use getElementById();

If Statement

let x = 1;
let y = 1;
if (x == y) {
  console.log("x and y are equal");
};

Loops

For loops

Work in progress.

While loops

Work in progress.