From Scratch to JavaScript
The same six ideas in blocks and in text: sequence, variable, condition, loop, function and event, plus what syntax and the console are.
Transcript
JavaScript is a programming language you write as text, and it is the language of web pages. The ideas are the same as in Scratch. Only the way you write them is different.
A sequence is lines that run from top to bottom. A variable is made with the word let. Let score equal zero, and later, score equals score plus one.
A condition is an if, with the test in round brackets. A loop is a for, and it counts how many times to repeat.
A function starts with the word function and a name, and you call it by name. An event handler runs when something happens, like a click.
Text code is strict. Brackets, quotes and semicolons must be exact. That spelling and punctuation is called syntax. When you make a mistake, the console shows an error message to help you find the bug.
Remember: JavaScript is a second language for the same six ideas. Syntax is its spelling rules, and the console shows the results and the errors.
More in this series
1:278What is a program?
A program is a list of exact instructions the computer follows in order. Algorithm, sequence and bug, explained with a robot that makes a sandwich.
1:079Events: when something happens
An event is something that happens, like a click or a key press, and an event handler is the script that runs when it does. Shown with Scratch blocks.
0:5810Loops: repeat instead of copy
A loop repeats blocks so you do not copy and paste them. Repeat, forever, and drawing shapes with a loop, shown with Scratch blocks.
1:0811Variables: a named box for a value
A variable holds a value under a name, and the value can change. Score, set and change, and what score = score + 1 means.
1:0112Conditions: if and else
A condition is a true or false question. If runs blocks when it is true, else runs when it is false. A fork in the road, with an umbrella or a hat.
1:1013Functions: name a group of blocks
A function is a named group of blocks you define once and call many times. Define, call and parameter, with a draw-a-square function.
1:1314Bugs and debugging
A bug is a mistake in a program. Debugging is finding it and fixing it: predict, run, compare, fix, shown on a square that does not close.