← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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