← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

  1. Hello, Riya!
  2. alert()
  3. 85
  4. 94
  5. if
  6. 92
  7. let
  8. 108
  9. a pop-up box
  10. 72
  11. .js
  12. Hi, Kabir!
  13. 96
  14. 42
  15. Welcome, Aman!
  16. 35
  17. 22
  18. 41
  19. actions and changes
  20. 31
  21. Welcome, Meera!
  22. 2
  23. let
  24. 29
  25. 32
  26. 72
  27. 31
  28. 17
  29. <script>
  30. 23
  31. 45
  32. 67
  33. 51
  34. 2
  35. 46
  36. console.log()
  37. 38
  38. 6
  39. 2
  40. Hello, Zoya!

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