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