patternjavascriptMinor
JavaScript Objects- Can you confirm?
Viewed 0 times
canobjectsyoujavascriptconfirm
Problem
Ok, I am in a JavaScript class, and I have no desire for anyone to do my schoolwork, I have already done what I think is correct, I am just hoping someone can take a look and tell me if I am close, or right, or whatever. Any feedback appreciated. Also, the instructor was very specific in saying that if it asks for a line of code, then just do a line of code- so if it appears things are missing that would be why.
1.Write a line of code using the Location object to return the uniform resource locator (URL) of a Web page to a variable called myWebPage.
2.Write a line of code using the Navigator object to return the Web browser name to a variable called myBrowserName.
3.Write a line of code using the Screen object to return the height of the display screen, not including operating system features such as the Windows Taskbar, to a variable called myScreenHeight
4.Write a line of JavaScript code using the Window object and other properties to open a new Web browser window with www.google.com displaying and no menu bar
That's it! Let me know if I did anything wrong, thank you!
1.Write a line of code using the Location object to return the uniform resource locator (URL) of a Web page to a variable called myWebPage.
function getLocation(){
alert(document.location);}2.Write a line of code using the Navigator object to return the Web browser name to a variable called myBrowserName.
function getLocation(){
alert(navigator.appName);}3.Write a line of code using the Screen object to return the height of the display screen, not including operating system features such as the Windows Taskbar, to a variable called myScreenHeight
function getLocation(){
alert("Total height is : "+screen.height);}4.Write a line of JavaScript code using the Window object and other properties to open a new Web browser window with www.google.com displaying and no menu bar
function getWindow(){
window.open('http://www.google.com','mywindow','width=400,height=200');}That's it! Let me know if I did anything wrong, thank you!
Solution
It looks like you're not following the instructions strictly. For example, here:
1.Write a line of code using the Location object to return the uniform resource locator (URL) of a Web page to a variable called myWebPage.
You didn't write a line of code, you wrote two, and you alerted the value instead of assigning to the variable. You also used a function, where the requirements do not include a function. I think the instructor is expecting something like this:
1.Write a line of code using the Location object to return the uniform resource locator (URL) of a Web page to a variable called myWebPage.
You didn't write a line of code, you wrote two, and you alerted the value instead of assigning to the variable. You also used a function, where the requirements do not include a function. I think the instructor is expecting something like this:
var myWebPage = window.location.href;Code Snippets
var myWebPage = window.location.href;Context
StackExchange Code Review Q#11255, answer score: 5
Revisions (0)
No revisions yet.