← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

HTML and CSS lesson 25: JavaScript basics · Set 652 · 40 questions
TalentJR

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

Answer key

  1. 19
  2. console.log()
  3. 33
  4. 2
  5. 59
  6. alert()
  7. in the console
  8. if
  9. 58
  10. 26
  11. Hello, Aman!
  12. Welcome, Arjun!
  13. let
  14. a pop-up box
  15. .js
  16. 86
  17. 3
  18. 4
  19. 33
  20. 63
  21. 6
  22. actions and changes
  23. 24
  24. 1
  25. Welcome, Riya!
  26. Welcome, Aman!
  27. 53
  28. Hi, Arjun!
  29. Well done, Riya!
  30. for
  31. 0
  32. 47
  33. Hi, Zoya!
  34. 48
  35. 29
  36. 61
  37. 7
  38. Welcome, Zoya!
  39. 3
  40. 11

Free html and css lessons, practice and worksheets at talentjr.in/html-css-for-kids