JavaScript Worksheet: Basics
Code tip (Line by line): let x = 5; makes a variable x holding 5; x = x + 2; changes it to 7. console.log(…) writes in the console; alert(…) shows a pop-up box. Text in quotes + anything = joined text: "5" + 3 → "53".
NameDateTime takenScore ___ / 40
- 1.⚡ Which JavaScript word makes a new variable? (a) console.log() (b) let (c) for (d) alert()
- 2.⚡ Which JavaScript word shows a pop-up box? (a) if (b) console.log() (c) let (d) alert()
-
3.⚡ What number does this code print?
let a = 42;
let b = 28;
console.log(a - b); - 4.⚡ A JavaScript file usually ends with which extension? (a) .css (b) .jpg (c) .html (d) .js
-
5.⚡ What does this code show?
let name = "Zoya";
alert("Welcome, " + name + "!"); (a) Welcome, Zoya! (b) Zoya (c) name (d) Welcome, name! - 6.⚡ What does alert() show? (a) a table (b) a pop-up box (c) a picture (d) a new tab
- 7.⚡ Which JavaScript word repeats code? (a) if (b) alert() (c) let (d) for
-
8.⚡ What does this code print? (Look at the quotes!)
let x = "9";
let y = 2;
console.log(x + y); (a) 11 (b) 92 (c) Error -
9.⚡ What number does this code print?
let a = 37;
let b = 8;
console.log(a - b); -
10.⚡ What number does this code print?
let apples = 10;
apples = apples + 2;
apples = apples - 9;
console.log(apples); -
11.⚡ What number does this code print?
let runs = 16;
runs = runs + 12;
runs = runs - 28;
console.log(runs); -
12.⚡ What number does this code print?
let books = 25;
books = books + 10;
books = books - 11;
console.log(books); -
13.⚡ What number does this code print?
let a = 50;
let b = 32;
console.log(a + b); -
14.⚡ What number does this code print?
let a = 33;
let b = 21;
console.log(a - b); -
15.⚡ What number does this code print?
let runs = 20;
runs = runs + 18;
runs = runs - 17;
console.log(runs); - 16.⚡ Which word makes a new variable? (a) put (b) give (c) make (d) let
- 17.⚡ Which JavaScript word writes in the console? (a) if (b) alert() (c) console.log() (d) let
-
18.⚡ What number does this code print?
let a = 45;
let b = 35;
console.log(a + b); -
19.⚡ What number does this code print?
let coins = 8;
coins = coins + 4;
coins = coins - 7;
console.log(coins); -
20.⚡ What number does this code print?
let a = 47;
let b = 13;
console.log(a + b); -
21.⚡ What number does this code print?
let a = 21;
let b = 12;
console.log(a - b); - 22.⚡ Which JavaScript word runs code when true? (a) alert() (b) if (c) let (d) console.log()
-
23.⚡ What does this code print? (Look at the quotes!)
let x = "2";
let y = 1;
console.log(x + y); (a) 3 (b) 21 (c) Error -
24.⚡ What number does this code print?
let a = 6;
let b = 12;
console.log(a * b); -
25.⚡ What does this code show?
let name = "Riya";
alert("Hello, " + name + "!"); (a) name (b) Riya (c) Hello, Riya! (d) Hello, name! -
26.⚡ What number does this code print?
let a = 12;
let b = 4;
console.log(a * b); -
27.⚡ What number does this code print?
let apples = 25;
apples = apples + 19;
apples = apples - 38;
console.log(apples); -
28.⚡ What does this code show?
let name = "Kabir";
console.log("Welcome, " + name + "!"); (a) Welcome, name! (b) Welcome, Kabir! (c) Kabir (d) name -
29.⚡ What does this code print? (Look at the quotes!)
let x = "9";
let y = 9;
console.log(x + y); (a) 18 (b) Error (c) 99 - 30.⚡ Where does console.log() show its output? (a) on the title bar (b) in the address bar (c) in the console (d) on the printer
-
31.⚡ What number does this code print?
let a = 6;
let b = 23;
console.log(a + b); - 32.⚡ Which tag holds JavaScript in a page? (a) <code> (b) <js> (c) <style> (d) <script>
-
33.⚡ What does this code show?
let name = "Aman";
console.log("Hi, " + name + "!"); (a) Aman (b) Hi, name! (c) name (d) Hi, Aman! -
34.⚡ What does this code show?
let name = "Aman";
console.log("Welcome, " + name + "!"); (a) name (b) Aman (c) Welcome, name! (d) Welcome, Aman! -
35.⚡ What does this code print? (Look at the quotes!)
let x = "5";
let y = 2;
console.log(x + y); (a) 52 (b) 7 (c) Error -
36.⚡ What number does this code print?
let a = 56;
let b = 40;
console.log(a + b); -
37.⚡ What number does this code print?
let a = 7;
let b = 6;
console.log(a * b); -
38.⚡ What does this code show?
let name = "Meera";
console.log("Welcome, " + name + "!"); (a) Welcome, Meera! (b) name (c) Welcome, name! (d) Meera - 39.⚡ What does JavaScript add to a web page? (a) the domain name (b) actions and changes (c) only colours (d) the page title
-
40.⚡ What number does this code print?
let a = 11;
let b = 4;
console.log(a + b);
Answer key
- let
- alert()
- 14
- .js
- Welcome, Zoya!
- a pop-up box
- for
- 92
- 29
- 3
- 0
- 24
- 82
- 12
- 21
- let
- console.log()
- 80
- 5
- 60
- 9
- if
- 21
- 72
- Hello, Riya!
- 48
- 6
- Welcome, Kabir!
- 99
- in the console
- 29
- <script>
- Hi, Aman!
- Welcome, Aman!
- 52
- 96
- 42
- Welcome, Meera!
- actions and changes
- 15
Free html and css lessons, practice and worksheets at talentjr.in/html-css-for-kids