← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

  1. 29
  2. 90
  3. a pop-up box
  4. 36
  5. 24
  6. <script>
  7. let
  8. 4
  9. 84
  10. Hello, Meera!
  11. 20
  12. 12
  13. for
  14. actions and changes
  15. 34
  16. 54
  17. 88
  18. Hi, Riya!
  19. in the console
  20. 73
  21. Hello, Arjun!
  22. console.log()
  23. 24
  24. alert()
  25. 17
  26. Hi, Meera!
  27. 64
  28. if
  29. Well done, Meera!
  30. 19
  31. 17
  32. 70
  33. 43
  34. 48
  35. 61
  36. 5
  37. 85
  38. Welcome, Aman!
  39. 5
  40. 79

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