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 writes in the console? (a) console.log() (b) for (c) let (d) if
- 2.⚡ Which JavaScript word shows a pop-up box? (a) for (b) if (c) alert() (d) console.log()
- 3.⚡ Which tag holds JavaScript in a page? (a) <js> (b) <style> (c) <code> (d) <script>
-
4.⚡ What number does this code print?
let coins = 25;
coins = coins + 16;
coins = coins - 41;
console.log(coins); - 5.⚡ What does JavaScript add to a web page? (a) the domain name (b) the page title (c) only colours (d) actions and changes
-
6.⚡ What does this code print? (Look at the quotes!)
let x = "8";
let y = 3;
console.log(x + y); (a) Error (b) 83 (c) 11 -
7.⚡ What does this code show?
let name = "Kabir";
console.log("Hi, " + name + "!"); (a) Kabir (b) Hi, name! (c) name (d) Hi, Kabir! -
8.⚡ What number does this code print?
let apples = 23;
apples = apples + 11;
apples = apples - 25;
console.log(apples); -
9.⚡ What number does this code print?
let a = 8;
let b = 34;
console.log(a + b); -
10.⚡ What number does this code print?
let apples = 26;
apples = apples + 18;
apples = apples - 10;
console.log(apples); -
11.⚡ What number does this code print?
let books = 8;
books = books + 11;
books = books - 18;
console.log(books); -
12.⚡ What does this code print? (Look at the quotes!)
let x = "5";
let y = 4;
console.log(x + y); (a) 54 (b) Error (c) 9 -
13.⚡ What does this code show?
let name = "Arjun";
alert("Well done, " + name + "!"); (a) name (b) Well done, name! (c) Well done, Arjun! (d) Arjun - 14.⚡ Where does console.log() show its output? (a) on the printer (b) in the console (c) in the address bar (d) on the title bar
- 15.⚡ Which JavaScript word makes a new variable? (a) if (b) console.log() (c) for (d) let
-
16.⚡ What number does this code print?
let a = 40;
let b = 25;
console.log(a - b); - 17.⚡ Which JavaScript word repeats code? (a) alert() (b) for (c) if (d) console.log()
-
18.⚡ What number does this code print?
let a = 12;
let b = 3;
console.log(a * b); -
19.⚡ What number does this code print?
let a = 3;
let b = 9;
console.log(a * b); - 20.⚡ Which word makes a new variable? (a) put (b) give (c) let (d) make
- 21.⚡ What does alert() show? (a) a new tab (b) a picture (c) a table (d) a pop-up box
-
22.⚡ What number does this code print?
let runs = 6;
runs = runs + 8;
runs = runs - 8;
console.log(runs); -
23.⚡ What does this code show?
let name = "Riya";
console.log("Well done, " + name + "!"); (a) Well done, Riya! (b) name (c) Well done, name! (d) Riya - 24.⚡ Which JavaScript word runs code when true? (a) alert() (b) console.log() (c) if (d) for
-
25.⚡ What does this code print? (Look at the quotes!)
let x = "8";
let y = 1;
console.log(x + y); (a) 81 (b) 9 (c) Error -
26.⚡ What does this code show?
let name = "Riya";
alert("Well done, " + name + "!"); (a) Well done, name! (b) Riya (c) name (d) Well done, Riya! -
27.⚡ What does this code show?
let name = "Riya";
alert("Hi, " + name + "!"); (a) name (b) Hi, name! (c) Riya (d) Hi, Riya! -
28.⚡ What number does this code print?
let books = 7;
books = books + 9;
books = books - 6;
console.log(books); -
29.⚡ What number does this code print?
let a = 4;
let b = 10;
console.log(a * b); -
30.⚡ What does this code print? (Look at the quotes!)
let x = "6";
let y = 5;
console.log(x + y); (a) 65 (b) 11 (c) Error -
31.⚡ What does this code show?
let name = "Aman";
alert("Welcome, " + name + "!"); (a) Aman (b) Welcome, name! (c) Welcome, Aman! (d) name -
32.⚡ What number does this code print?
let apples = 8;
apples = apples + 14;
apples = apples - 17;
console.log(apples); -
33.⚡ What does this code print? (Look at the quotes!)
let x = "8";
let y = 6;
console.log(x + y); (a) 86 (b) 14 (c) Error - 34.⚡ A JavaScript file usually ends with which extension? (a) .jpg (b) .css (c) .js (d) .html
-
35.⚡ What does this code print? (Look at the quotes!)
let x = "2";
let y = 4;
console.log(x + y); (a) Error (b) 6 (c) 24 -
36.⚡ What does this code print? (Look at the quotes!)
let x = "5";
let y = 6;
console.log(x + y); (a) 11 (b) 56 (c) Error -
37.⚡ What number does this code print?
let a = 55;
let b = 5;
console.log(a + b); -
38.⚡ What does this code show?
let name = "Aman";
console.log("Hello, " + name + "!"); (a) name (b) Aman (c) Hello, name! (d) Hello, Aman! -
39.⚡ What number does this code print?
let a = 2;
let b = 4;
console.log(a * b); -
40.⚡ What number does this code print?
let a = 40;
let b = 13;
console.log(a - b);
Answer key
- console.log()
- alert()
- <script>
- 0
- actions and changes
- 83
- Hi, Kabir!
- 9
- 42
- 34
- 1
- 54
- Well done, Arjun!
- in the console
- let
- 15
- for
- 36
- 27
- let
- a pop-up box
- 6
- Well done, Riya!
- if
- 81
- Well done, Riya!
- Hi, Riya!
- 10
- 40
- 65
- Welcome, Aman!
- 5
- 86
- .js
- 24
- 56
- 60
- Hello, Aman!
- 8
- 27
Free html and css lessons, practice and worksheets at talentjr.in/html-css-for-kids