Lesson 5: DOM Objects and Built-In Objects Flashcards
What is BOM (DOM)?
the Browser Object Model.
What are two window methods?
alert() and prompt()
What is returned if the user clicks the cancel button on a prompt popup?
Null value.
What does confirm(“msg”) do?
Return true or false depending on which button is clicked on the popup.
Show an example of confirm():
let answer = confirm("is 3+2=5?"); if (answer==true) (alert("correct"); } else {alert("wrong"); }
What does getElementBiId() do?
Returns a reference to an element with the id specified.
Show an example of getElementById:
const h1 = document.getElementById('title');
What is innerHTML used for?
Setting or changing element content.
What does the window.history object do?
Stores a list of the URLs previously visited using the current browser tab.
What does the location object contain?
Information about the currently loaded page.
What does the navigator object contain?
Data about the browser application.
Math.abs(a):
Returns the absolute value of a.
Math.celi(a):
Rounds a up to the next integer.
Math.floor(5.8):
Rounds a down to the next integer.
Math.round(a):
Rounds a to the nearest integer.
Math.sqrt(a):
Returns the square root of a.
Math.max():
Gets the max value of its arguments.
Math.min():
Gets the min value of its arguments.
Math.random():
Creates random numbers between 0 and 1.
Show a display of a random integer between 1 and 10:
let randomNum = Math.floor((Math.random() * 10) + 1); let el = document.getElementById('info'); el.innerHTML = '<h1>random number</h1><p>' + randomNum + '</p>';
What does the keyword ‘with’ do?
Takes an object as an argument and is followed by a code block.
Show an example using the ‘with’ keyword:
with (math) { var myRand = random(); var biggest = max(3,4,5); var height = round(76.35); }
Create a date object with today’s date:
let myDate = new Date();
Other ways to create a Date object:
- new Date()
- new Date(year, month, day, hrs, mins, secs, milliseconds)
- new Date(milliseconds)
- new Date(date string)
What does alert() do?
Pauses all user interaction with the page until the user clears the dialog.
Show an example of alert()
alert(“this is my message!”);
What does prompt() do?
Opens a modal dialog, allowing users to enter information.
Show an example of a prompt():
var answer = prompt(“What is your name?”, “John Doe”);