← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

  1. alert()
  2. 15
  3. 72
  4. 21
  5. if
  6. let
  7. <script>
  8. 33
  9. let
  10. 28
  11. a pop-up box
  12. 51
  13. 65
  14. Hi, Arjun!
  15. 61
  16. console.log()
  17. 55
  18. actions and changes
  19. for
  20. 97
  21. 19
  22. 25
  23. Hello, Zoya!
  24. 21
  25. 65
  26. 68
  27. 47
  28. 25
  29. 31
  30. Hi, Meera!
  31. 35
  32. 98
  33. 20
  34. in the console
  35. 36
  36. 24
  37. 30
  38. 5
  39. 9
  40. 32

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