Take the 2-minute tour ×
Code Review Stack Exchange is a question and answer site for peer programmer code reviews. It's 100% free, no registration required.

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!

share|improve this question

migrated from stackoverflow.com Apr 27 '12 at 18:38

This question came from our site for professional and enthusiast programmers.

    
@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. –  Jonathan Sampson Apr 27 '12 at 18:37
add comment

3 Answers 3

up vote 1 down vote accepted

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.

share|improve this answer
    
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" :/ –  Corbin Holbert Apr 27 '12 at 22:40
    
You could remove it from the function, the inner line is all you really need. –  jzworkman Apr 27 '12 at 22:51
add comment

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;
share|improve this answer
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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