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