3
\$\begingroup\$

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.

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!

\$\endgroup\$
1
  • \$\begingroup\$ @CorbinHolbert This may be better for our Code Review site. I'll migrate it for you, and then you can watch there as people help evaluate your code. \$\endgroup\$
    – Jonathan Sampson
    Apr 27, 2012 at 18:37

3 Answers 3

2
\$\begingroup\$

Three small changes for numbers 1, 2, and 3 as it says they should be assigned to variables.

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.

var myWebPage = document.location.href;

2.Write a line of code using the Navigator object to return the Web browser name to a variable called myBrowserName.

var myBriowserName = 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

var myScreenHeight = screen.height;

Otherwise it looks good at first glance.

\$\endgroup\$
2
  • \$\begingroup\$ So I did number four right though? I guess I was overcomplicating things. At first I had exactly what you just typed up and I looked at it and thought "no way, that's too simple" :/ \$\endgroup\$ Apr 27, 2012 at 22:40
  • \$\begingroup\$ You could remove it from the function, the inner line is all you really need. \$\endgroup\$
    – jzworkman
    Apr 27, 2012 at 22:51
5
\$\begingroup\$

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:

var myWebPage = window.location.href;
\$\endgroup\$
2
\$\begingroup\$

Give up on putting everything in functions, especially when the question does not ask for a function but for a line of code (it probably means "a single statement").

Pay attention when the question requests that the value be put in a variable.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.