← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

  1. if
  2. 26
  3. 36
  4. in the console
  5. a pop-up box
  6. let
  7. 2
  8. Well done, Riya!
  9. 14
  10. .js
  11. <script>
  12. 13
  13. 36
  14. 50
  15. Hi, Kabir!
  16. 5
  17. 2
  18. 48
  19. 96
  20. 52
  21. 13
  22. 85
  23. Welcome, Arjun!
  24. Hello, Aman!
  25. alert()
  26. 71
  27. 26
  28. console.log()
  29. 89
  30. 20
  31. 10
  32. 50
  33. 64
  34. 17
  35. 6
  36. actions and changes
  37. 47
  38. 33
  39. 33
  40. 2

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