JavaScript

Cards (52)

  • What is required to run JavaScript?
    A browser
  • How do you include JavaScript in an HTML document?
    Add JavaScript code between <script> tags
  • What is the purpose of the <title> tag in an HTML document?
    It sets the title of the web page
  • What command is used to display an alert in JavaScript?
    window.alert()
  • What is the key difference in syntax between JavaScript and Python?
    JavaScript uses curly brackets, Python uses indentation
  • What command is used in Python to output to the console?
    print
  • How can you output to the browser's console in JavaScript?
    Using console.log()
  • What keyboard shortcut opens the console in most browsers?
    Control-Shift-J
  • How can you display output in a pop-up window in JavaScript?
    Using window.alert()
  • What does document.write() do in JavaScript?
    It outputs directly onto the HTML page
  • What is the purpose of the .innerHTML property in JavaScript?
    To change the value of HTML elements
  • How do you declare a variable in JavaScript?
    Using the var command
  • How does JavaScript handle data types for variables?
    It does not differentiate between integer and float
  • What is a versatile way to get user input in JavaScript?
    Create a form on the page
  • What is the focus of the spec regarding input methods in JavaScript?
    Focus is on using the input once received
  • What is the purpose of the switch structure in JavaScript?
    To handle multiple conditions
  • How does a simple if statement differ between Python and JavaScript?
    JavaScript uses parentheses and curly brackets
  • What is the syntax for a for loop in JavaScript?
    for (let i = 0; i < 10; i++)
  • How do you iterate through a list in JavaScript?
    Using for (let i of list)
  • What is the syntax for a while loop in JavaScript?
    while (condition) {}
  • What is the purpose of the do...while loop in JavaScript?
    To execute code at least once
  • What is the JavaScript equivalent of Python's 'and' logical operator?
    &&
  • How do you concatenate two strings in JavaScript?

    Using str.concat(str)
  • What is the output of str.charAt(3) in JavaScript?
    Character in the 3rd position
  • What are the exercises to practice JavaScript input handling?
    1. Create a page with two input boxes for name and number.
    2. Create a page with two input boxes for two numbers, output the larger.
    3. Create a page with three input boxes for three numbers, output the smallest.
    4. Create a page for a times table based on user input.
    5. Create a page to find the sum of integers between two numbers.
    6. Create a page to return all integers between two given numbers.
    7. Create a page to rearrange digits of a three-digit number for maximum value.
  • What are common string manipulation functions in JavaScript?
    • str.charAt(index): Return character at index
    • str.substring(start, end): Return substring from start to end
    • str.length: Return length of string
    • str.indexOf('x'): Find first occurrence of 'x'
    • str.split(): Split string into array
    • str.concat(str): Concatenate two strings
    • str.trim(): Remove whitespace from ends
    • str.replace(a, b): Replace occurrences of 'a' with 'b'
  • What is the output of str.length in JavaScript?
    Length of the string
  • How do you find the first occurrence of a character in a string in JavaScript?
    Using str.indexOf('x')
  • What is the output of str.split(',') in JavaScript?
    Array of strings split at ','
  • What is the purpose of the exercises related to string manipulation?
    To practice JavaScript string handling
  • What is the output of str.replace(a, b) in JavaScript?
    Replace occurrences of 'a' with 'b'
  • What does str.trim() do in JavaScript?
    Removes whitespace from the beginning and end
  • How can you check if two strings are palindromes in JavaScript?
    By comparing the strings in reverse
  • How can you extract the domain name from an email address in JavaScript?
    By splitting the string at '@'
  • What is the output of reversing a string in JavaScript?
    The string written backwards
  • How can you ensure an email address does not exceed a certain length in JavaScript?
    By cutting the length of names if needed
  • What is the purpose of the exercises related to user input?
    To practice handling user input in JavaScript
  • What is the output of the exercise that asks for a times table?
    Prints the times table for the given number
  • What is the output of the exercise that asks for the smallest of three numbers?
    Outputs the smallest of the three numbers
  • What is the output of the exercise that sums integers between two numbers?
    Returns the sum of all integers between