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