Week 9

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to Lesson

Podcast

Play an AI-generated podcast conversation about this lesson
Download our mobile app to listen on the go
Get App

Questions and Answers

What is the primary function of built-in objects in JavaScript?

  • To define user interfaces
  • To manage database connections
  • To provide functionalities out of the box (correct)
  • To enhance graphical processing

Which of the following accurately describes the Document Object Model (DOM)?

  • It is the structure of JavaScript code.
  • It solely enables CSS styling.
  • It allows JavaScript to interact with browser content. (correct)
  • It represents the programming interface for web servers.

Which syntax is correct to return the square root of $\frac{1}{2}$?

  • Math.SQRT2
  • Math.PI
  • Math.E
  • Math.SQRT1_2 (correct)

Which method is used to find the highest value among given numbers?

<p>Math.max(x,y,z,...n) (A)</p>
Signup and view all the answers

What statement about the Date object is false?

<p>It can format dates but cannot get the current date. (D)</p>
Signup and view all the answers

What is the correct syntax to round a number down to its nearest integer?

<p>Math.floor(x) (C)</p>
Signup and view all the answers

Which Math property is not commonly accessed using the Math object?

<p>Math.COS (A)</p>
Signup and view all the answers

Which method would you use to obtain the logarithm base 10 of $e$?

<p>Math.LOG10E (B)</p>
Signup and view all the answers

What is the output of Math.random()?

<p>Returns a random number between 0 and 1 (D)</p>
Signup and view all the answers

Which of the following describes a property of JavaScript Math methods?

<p>Math methods provide mathematical calculations (D)</p>
Signup and view all the answers

What is the correct method to load a new document using the window location object?

<p>window.location.assign() (B)</p>
Signup and view all the answers

Which methods can be called to navigate backwards and forwards in the history list?

<p>history.back() and history.forward() (D)</p>
Signup and view all the answers

Which of the following are the correct types of window popup boxes?

<p>Alert box, confirm box and prompt box (C)</p>
Signup and view all the answers

What type of popup box requires the user to click 'OK' to proceed?

<p>Alert Box (D)</p>
Signup and view all the answers

What is the key characteristic of a Confirm Box?

<p>It allows a decision by clicking 'OK' or 'Cancel'. (B)</p>
Signup and view all the answers

Which statement about the prompt box is untrue?

<p>If 'OK' is clicked, the box returns true. (D)</p>
Signup and view all the answers

Which statement does not pertain to the concept of HTML DOM?

<p>JS can create new HTML attributes. (B)</p>
Signup and view all the answers

Which method is best for accessing elements by class name in the document object?

<p>document.getElementByClassName(name) (D)</p>
Signup and view all the answers

What is the easiest way to modify the content of an HTML element?

<p>By using innerHTML property (C)</p>
Signup and view all the answers

Which method allows you to set date values for a date object?

<p>Date Set Method (B)</p>
Signup and view all the answers

What method is used to retrieve the character at a specified index in a string?

<p>charAt() (C)</p>
Signup and view all the answers

Which methods are used to extract a portion of a string and split a string into an array?

<p>Substring() and split() (A)</p>
Signup and view all the answers

Which model allows JavaScript to interact with browser-specific functionalities?

<p>Browser Object Model (A)</p>
Signup and view all the answers

Objects in JavaScript act as containers for which two components?

<p>Properties and methods (D)</p>
Signup and view all the answers

Which built-in object is designed for performing mathematical operations?

<p>JavaScript Math object (C)</p>
Signup and view all the answers

What objects are part of the Browser Object Model (BOM)?

<p>Window, Navigator, Location, History and Screen (B)</p>
Signup and view all the answers

Which method under the window object is used to close the current window?

<p>Window.close() (D)</p>
Signup and view all the answers

To return the width of the user's screen in pixels minus interface features, which method should be used?

<p>Screen.availWidth (A)</p>
Signup and view all the answers

To obtain the URL of the current page using the window location object, which property should be accessed?

<p>Window.location.href (A)</p>
Signup and view all the answers

What syntax correctly changes the content of an HTML element?

<p>document.getElementById('demo').innerHTML = 'Hello World!'; (C)</p>
Signup and view all the answers

Which option demonstrates the correct way to modify an element's style?

<p>document.getElementById(id).style.property = new style (C)</p>
Signup and view all the answers

Which of the following is NOT considered an event in JavaScript?

<p>The page is locked (B)</p>
Signup and view all the answers

What is incorrect about the following syntax for changing element content: document.getElementById('demo').innetHTML = 'Hello World!'; ?

<p>innetHTML is a typo; it should be innerHTML (C)</p>
Signup and view all the answers

Which code will successfully change the text color to blue upon a button click?

<p><button onclick='document.getElementById("p2").style.color = "blue";'>Click Me!</button> (C)</p>
Signup and view all the answers

Which activity does NOT generate an event in the HTML DOM?

<p>The browser is minimized (A)</p>
Signup and view all the answers

Identifying a correct action, what does document.getElementById('p2').style.color = 'blue'; accomplish?

<p>It sets the text color of element p2 to blue. (B)</p>
Signup and view all the answers

How can you ensure code runs after the webpage finishes loading?

<p>Using the window.onload function (D)</p>
Signup and view all the answers

In JavaScript, what does the syntax document.getElementById(id).style.property = new style aim to achieve?

<p>Modifying the visual style property of an element (D)</p>
Signup and view all the answers

What JavaScript code snippet will correctly change the text displayed in an element with id 'demo'?

<p>document.getElementById('demo').innerHTML = 'Hello World!'; (C)</p>
Signup and view all the answers

Flashcards

Built-in Objects

Pre-defined objects in JavaScript that offer ready-made functionalities.

DOM (Document Object Model)

A programming interface for creating, changing or removing elements (content) from a document.

Math.SQRT2

Returns the square root of 2.

Math.LN10

Returns the base-10 logarithm of 10.

Signup and view all the flashcards

Math.min()

Returns the smallest number in a list of numbers.

Signup and view all the flashcards

Math.floor()

Rounds a number down to the nearest whole number.

Signup and view all the flashcards

Date object

Represents dates and times, used to manipulate dates and times in JavaScript.

Signup and view all the flashcards

Math.properties

Mathematical constants provided in JavaScript that can be directly accessed.

Signup and view all the flashcards

Math methods

Mathematical functions available in JavaScript that perform actions on numbers.

Signup and view all the flashcards

Date Methods

Methods used to manipulate, extract or set components of Date objects in JavaScript.

Signup and view all the flashcards

Date object setting

Methods to set date-related values (years, days, etc.) in a date object.

Signup and view all the flashcards

String Object Manipulation

A JavaScript object for storing and interacting with sequences of characters.

Signup and view all the flashcards

charAt() method

Retrieves a character at a given index in a string.

Signup and view all the flashcards

String extraction methods

Substring() and split() methods are used for extracting segments and splitting strings into parts respectively

Signup and view all the flashcards

Browser Object Model (BOM)

A set of objects in JavaScript for interacting with the browser's window, document, and other browser-specific functionalities.

Signup and view all the flashcards

JavaScript Objects

Contain properties (data) and methods (actions).

Signup and view all the flashcards

JavaScript Math object

Provides mathematical functions.

Signup and view all the flashcards

BOM objects

Window, Navigator, Location, History, and Screen objects.

Signup and view all the flashcards

Window.close()

Closes the current window.

Signup and view all the flashcards

Screen.availWidth

Returns the width of the visitor's screen in pixels, excluding interface elements like the taskbar.

Signup and view all the flashcards

Window Location Object

A built-in JavaScript object that provides information and control over the current URL of a web page.

Signup and view all the flashcards

window.location.assign()

A method of the Window Location object that loads a new document into the current window. It allows to navigate to a different URL.

Signup and view all the flashcards

window.location.hostname

A property of the Window Location object that returns the domain name of the current URL.

Signup and view all the flashcards

window.history

A built-in JavaScript object that gives access to the user's browsing history within the current window.

Signup and view all the flashcards

history.back() and history.forward()

Methods of the Window History object that allow navigation to the previous or next page in the browsing history.

Signup and view all the flashcards

Alert Box

A standard popup window used to display messages or notifications to the user.

Signup and view all the flashcards

Confirm Box

A popup window that asks the user for confirmation or agreement. It has two buttons: 'OK' and 'Cancel'.

Signup and view all the flashcards

Prompt Box

A popup window that prompts the user for input, such as a text value or a number.

Signup and view all the flashcards

document.getElementByClassName()

A method in the Document object used to retrieve an HTML element based on its class name.

Signup and view all the flashcards

innerHTML property

A property of HTML elements that allows for modifying the content of an element. It lets you change the text, structure, or other content within an HTML element.

Signup and view all the flashcards

Change HTML content

To modify the text or structure inside an HTML element using JavaScript.

Signup and view all the flashcards

Change HTML style

To modify the visual appearance of an HTML element using JavaScript, such as color, font, or size.

Signup and view all the flashcards

HTML events

Actions that trigger JavaScript code, such as clicking a button, changing text, or loading a webpage.

Signup and view all the flashcards

Event Handling

The process of executing code when an event occurs in a web page, using JavaScript.

Signup and view all the flashcards

Click Event

An event that occurs when the user clicks on an HTML element, triggering JavaScript code.

Signup and view all the flashcards

Load Event

An event that occurs when an entire webpage has finished loading, triggering JavaScript code.

Signup and view all the flashcards

Change Event

An event that occurs when the value of an input field, like a text box, is modified by the user.

Signup and view all the flashcards

JavaScript to change style on click

A JavaScript code snippet used to modify the style of an HTML element when a button is clicked.

Signup and view all the flashcards

innerHTML

A JavaScript property that allows you to get or set the HTML content of an element.

Signup and view all the flashcards

style property

A JavaScript property used to access and modify the CSS style attributes of an element.

Signup and view all the flashcards

Study Notes

Built-in Objects

  • Pre-defined objects providing various functionalities
  • Included right away

Document Object Model (DOM)

  • JavaScript interacts with the browser
  • Includes objects like Window, Navigator, Location, History, Screen
  • Allows JavaScript to interact with the browser window, document, and other browser-specific functionalities
  • Enables creation, modification, and removal of document elements

Mathematical Constants and Methods

  • Math.SQRT1_2: Returns the square root of 1/2
  • Math.LOG10E: Returns the base-10 logarithm of Euler's number (e)
  • Math.min(): Returns the lowest value among the provided numbers
  • Math.max(): Returns the highest value among the provided numbers
  • Math.abs(): Returns the absolute value of a number
  • Math.random(): Returns a random number between 0 (inclusive) and 1 (exclusive)
  • Math.round(): Rounds a number to the nearest integer
  • Math.ceil(): Rounds a number up to the nearest integer
  • Math.floor(): Rounds a number down to the nearest integer

Date Object

  • Represents dates and times
  • Includes year, month, day, hour, minute, and second
  • Retrieves the current date and time
  • Creates date/time values
  • Allows manipulation of date-related information

String Object

  • Sequence of characters
  • Provides methods for manipulating and working with strings

String Object Methods

  • charAt(): Retrieves the character at a specified index
  • substring(): Extracts a portion of a string
  • split(): Divides a string into an array of substrings

Window Object

  • Interaction with the browser window
  • window.location.href: Retrieves the URL (Uniform Resource Locator) of the current web page
  • window.location.assign(): Loads a new document into the browser by navigating to a new URL.
  • window.close(): Closes the current window
  • window.open(): Opens a new browser window
  • screen.width: Retrieves the width of the browser's screen in pixels
  • screen.height: Retrieves the height of the browser's screen in pixels
  • screen.availWidth: Retrieves the width of the screen available for the application, minus the operating system's interface elements.
  • screen.availHeight: Retrieves the height of the screen available for the application, minus the operating system's interface elements.

Window Popup boxes

  • Alert box: Displays a message to the user, prompting a single "OK" button
  • Confirm box: Displays a message with a "OK" button and a "Cancel" button
  • Prompt box: Displays a message and input field, allowing the user to enter a value. Informs the user to make sure about needed actions

HTML DOM

  • Provides a way of accessing and modifying elements in HTML (HyperText Markup Language)
  • document.getElementById(): retrieves the element with the corresponding ID.
  • document.getElementsByTagName(): retrieves all elements with the corresponding tag.
  • document.getElementsByClassName(): retrieves all elements of the specified class.
  • innerHTML: Modifies the content within an HTML element
  • style: Modifies the CSS style attributes

HTML Events

  • Execution of code when an event occurs on an HTML element
  • Events are automatically triggered by the browser (e.g. page load, clicks, input changes)

Studying That Suits You

Use AI to generate personalized quizzes and flashcards to suit your learning preferences.

Quiz Team

Related Documents

JS WK9 PDF
Use Quizgecko on...
Browser
Browser