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