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