← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

  1. actions and changes
  2. 80
  3. 29
  4. Hello, Riya!
  5. 8
  6. .js
  7. 91
  8. 72
  9. 8
  10. 5
  11. 57
  12. for
  13. <script>
  14. Welcome, Meera!
  15. let
  16. 9
  17. Hello, Arjun!
  18. console.log()
  19. if
  20. Hello, Riya!
  21. let
  22. a pop-up box
  23. Well done, Riya!
  24. in the console
  25. 91
  26. 43
  27. 63
  28. 54
  29. 14
  30. 25
  31. 5
  32. 9
  33. 50
  34. 18
  35. 110
  36. Well done, Arjun!
  37. 3
  38. 66
  39. 11
  40. 33

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