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