Chapter 10 : JavaScript Part 3 Flashcards

1
Q

What information does the window.screen object contains?

A
  1. Information about the user’s screen
  • It can be written without the window prefix

screen.width
screen.height

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What value does screen.width returns?

A
  1. Returns the width of the visitor’s screen in pixels
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What value does screen.height returns?

A
  1. Returns the height of the visitor’s screen in pixels
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What value does screen.availWidth returns?

A
  1. Returns the width of the visitor’s screen ( pixels ), minus interface features like the windows taskbar
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What value does screen.availHeight returns?

A
  1. Returns the height of the visitor’s screen ( pixels ), minus interface features like the windows taskbar
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What value does screen.colorDepth returns?

A
  1. Returns the number of bits used to display 1 color
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What value does screen.pixelDepth returns?

A
  1. Returns the pixel depth of the screen
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Write a JavaScript code to view screen width and height with id demo and demo2?

A
<script>
document.getElementById("demo").innerHTML = "Screen Width  : " + screen.width;
document.getElementById("demo2").innerHTML = "Screen Height  : " + screen.height;
</script>

<p></p>

<p></p>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Write a JavaScript code to view screen available width and height with id demo and demo2?

A
<script>
document.getElementById("demo").innerHTML = "Screen Avail Width  : " + screen.availWidth;
document.getElementById("demo2").innerHTML = "Screen Avail Height  : " + screen.availHeight;
</script>

<p></p>

<p></p>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Write a JavaScript code to view color depth and pixel depth with id demo and demo2?

A
<script>
document.getElementById("demo").innerHTML = "Color Depth  : " + screen.colorDepth;
document.getElementById("demo2").innerHTML = "Pixel Depth  : " + screen.pixelDepth;
</script>

<p></p>

<p></p>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What can window.location object be used?

A
  1. Used to get the current page address ( URL ) and to redirect the browser to a new page
  • It can also be written without using the window prefix
    window.location.href -> location.href
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What does window.location.href do and what does it return?

A
  1. Returns the href ( URL ) of the current page
  2. http://www.apu.edu.my/index.html
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What does window.location.hostname do and what does it return?

A
  1. Returns the domain name of the web host
  2. www.apu.edu.my
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What does window.location.[athname do and what does it return?

A
  1. Returns the path and filename of the current page
  2. /explore-apu/university/index.html
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What does window.location.protocol do and what does it return?

A
  1. Returns the web protocol used
  2. http : / https:
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What does window.location.assign() do and what does it return?

A
  1. Loads a new document
  2. Loads a new document on current document
17
Q

What object contains the browsers history?

A
  1. window.history
  • It can also be written without the window prefix
18
Q

List out 2 methods for how JavaScript can access user browsing history

A
  1. history.back()
  2. history.forward()
  • There are some limitations to protect the privacy of the users
19
Q

What are the time intevals called and what can it do?

A
  1. Timing Events
  2. Execution of code at specified time intervals
20
Q

List out 2 key methods for Timing Events

A
  1. setTimeout ( function , milliseconds)
    • Executes a function after waiting a specified number of milliseconds
  2. setInterval ( function, milliseconds )
    • Same as setTimeout but repeats the execution of the function

<button>Try it</button>

<button>Try it</button>

  • Can also use with window prefix

<button>Try it</button>

21
Q

What does clearTimeout() do?

A
  1. Stops the execution of the function specified in setTimeout()
22
Q

What is the syntax for clearTimeout?

A
  1. window.clearTimeout(timeoutVariable)
  2. clearTimeout(timeoutVariable)
  • Uses the variable returned from setTimeout()

myVar = setTimeout(function, milliseconds);
clearTimeout(myVar);

  • We can also stop the execution by calling the clearTimeout() method
23
Q

What method can we use to stop the setInterval() method?

A
  1. clearInterval()
  • myVar = setInverval( function, milliseconds );
    clearInterval(myVar);
24
Q

What does cookies do?

A
  1. Allow website to store user information in web page for faster login, performance
  • Data stored in small text files , on user’s computer
25
What problem does cookies solved?
1. How to remember information about the user
26
What JavaScript property is used to store cookies?
1. document.cookie
27
How to create cookie to store username John Doe?
document.cookie = "username=John Doe";
28
Set the cookie username John Doe and expiry date and then the path
document.cookie = "username=John Doe"; expires = Thu, 18 Dec 2017 12:00:00 UTC ; path="/";
29
What is the default value for path?
1. By default, the cookie belongs to the current page
30
How to read the cookie?
var username = document.cookie; * document.coockie will return all cookies in one string like cookie1 = value ; cookie2 = value ; cookie3 = value