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