← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

  1. <script>
  2. Hello, Arjun!
  3. 33
  4. Hello, Kabir!
  5. 86
  6. in the console
  7. 9
  8. 21
  9. .js
  10. for
  11. 24
  12. let
  13. 63
  14. 12
  15. 5
  16. let
  17. actions and changes
  18. 6
  19. 12
  20. 28
  21. 19
  22. 51
  23. 15
  24. 14
  25. Welcome, Arjun!
  26. 36
  27. 42
  28. 5
  29. Hi, Kabir!
  30. 23
  31. 20
  32. 1
  33. Hello, Riya!
  34. alert()
  35. Welcome, Meera!
  36. if
  37. 4
  38. Welcome, Riya!
  39. console.log()
  40. 28

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