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