← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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