Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Desperately seeking JavaScript help with school project...
Old 09-05-2008, 04:06 PM Desperately seeking JavaScript help with school project...
Novice Talker

Posts: 8
Name: Mary
Trades: 0
Hello,

I am new to these forums and very, very new to JavaScript. I am taking a class this semester at our local community college on JavaScript. We are using the book " Essentials for design, JavaScript Comprehensive" by Michael Brooks as well as a web site (mounted on Blackboard) on JavaScript design by our instructor. Basicly all the website involves is pull down menus with samples of code and no explanations. For me, there is no logic behind it and I really like to know what I am writing when I am writing code. So now to why I am so desperate....I have two projects I am working on that on due ASAP (actually they are probably overdue by now) but I can't seem to get them to work. At this point, I am totally confused as to what I am writing and the more I work on them the more confused I get....my instructor just refers me to the website which is making no sense to me. So I would like to know if anyone can please help me out here and if you can give me any help, please offer some explanations as to where I went wrong so I can learn and not make the same mistake again.

Project 1...we are suppose to complete a web page provided. Add functionality by giving the function a name, create a variable that instantiates a new date variable, create a variable that gets the date from the variable previously created, add a conditional to the IF statement that checks to see if the variable created is equal to 1, create a single line statment block that opens a new window with the to following information (window source url, http://www.ibm.com, window name - quiz2, options - width 400, height 200), add an alert command that displays the follwoing message in case the day is not Monday, add the appropriate event handler to the input tag to call the user defined function. No paramenters are passed to the function.

Here is the original code the instructor gave us to work with:

<html>
<head><title>Quiz 2</title>
<script language="javascript">
function function_name(){ //replace function_name with a valid function name
var variableName = ??; //finish the var statement to create a new Date variable
var variableName = variableName.method; //finish the var statement to extract the day of the Week from the Date variable above
if(conditional){ //add a conditional that checks to see if the day of the week is Monday
Open a new window showing IBM’s site
}
else{
Display the message in an alert box
}
}
</script>
</head>
<body>
<input type="button" name="dispbutton" value="Display IBM" event handler to call the function in line 4 to display the IBM site in a new window>
</body>
</html>


Here is what I have managed to do...if I take out the If/Else statement the pop up works but if I leave that statement in nothing happens....so where did I go wrong.

<html>
<head><title>Quiz 2</title>
<script language="javascript">

myPopUp= window.open("http://www.ibm.com", "myPopUp")
var currentTime = new Date();
var specificDate = new Date();
if(specificdate == 1){
window.open("http://www.ibm.com", "quiz2","width=400","height="200");
}
else{
alert ("Today is not Monday. Please try again as soon as it is Monday.");
}

</script>
</head>
<body>
<input type="button" name="dispbutton" value="Display IBM" onClick = "window.open">
</body>
</html>


Thanks for any and all help with this,
Mary Anne
Mary Anne is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 09-05-2008, 04:33 PM Re: Desperately seeking JavaScript help with school project...
vangogh's Avatar
Post Impressionist

Posts: 10,689
Name: Steven Bradley
Location: Boulder, Colorado
Trades: 0
Hi Mary Anne. Welcome to Webmaster-Talk.

One thing wrong with the if statement is a simple one to fix. Looks like you have a typo. The variable you defined is called specificDate and then you use specificdate in the conditional. That D/d thing is important. The case does matter. As far as your code is concerned there is no variable called specificdate with the lower case 'd' and so it always fails your test.

However there's still a little more to do to get things working. new Date() is creating a Date object. It has functions associated with it to allow you to find more information about the date. The one you'll want is getDay(), which will return a number representing the day of the week. 0 will correspond to Sunday, 1 to Monday...6 to Saturday.

In your script after you set currentTime to be a new Date object you could then say

var specificDate = currentTime.getDay();

specificDate will then be equal to a number between 1 and 6. You can then test using the conditional if just like you are (but remember to fix the typo)

A better name for currentTime is probably currentDate, since it's really the date getting stored and not just the time. I'd then use something like today as the name for the second variable so

I think everything else will work after the fixes above.

I hope that helps.

Also here's a good JavaScript tutorial from W3Schools. W3Schools has good intro tutorials in general. They're usually easy to understand and quick to work through. I'd bet many of us here went through one of more of them while we were getting started. I know I did. They won't teach you everything, but they can teach you a lot.

One last thing I'll add is if it were me I'd use different names for your variables. It won't affect the script working, but it's good to use names the best describe what the variable will store.

currentDate = new Date();
today = currentDate.getDay();

Those aren't necessarily the only or even the best names, but you'll find down the road if you name things well it's much easier to go back to a program later and understand what it's doing. Not a big deal in something like this, but it really does help a lot with bigger programs.
__________________
l Search Engine Friendly Web Design |
Please login or register to view this content. Registration is FREE

l Tips On Marketing, SEO, Design, and Development |
Please login or register to view this content. Registration is FREE

l
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

Last edited by vangogh; 09-05-2008 at 04:41 PM..
vangogh is offline
Reply With Quote
View Public Profile Visit vangogh's homepage!
 
Old 09-05-2008, 04:34 PM Re: Desperately seeking JavaScript help with school project...
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,528
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
http://www.w3schools.com/jS/js_obj_date.asp

http://www.w3schools.com/jsref/jsref_obj_date.asp
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 09-05-2008, 06:03 PM Re: Desperately seeking JavaScript help with school project...
Novice Talker

Posts: 8
Name: Mary
Trades: 0
Question...so I change what you said but I still can't get it to pull any thing up. So my question is....for the first line where I am suppose to call a function, do I have to have it written like this (I changed what I called my popup window and rewrote my function) or does my window.open have to be equal to something within my function?

function myPopUp(){

var currentDate = new Date();
var specificDate = currentDate.getDay();
If(specificDate == 1){
window.open("http://www.ibm.com", "quiz2","width=400","height="200");
}
Else{
alert ("Today is not Monday. Please try again as soon as it is Monday.");
}
}
</script>
</head>
<body>
<input type="button" name="dispbutton" value="Display IBM" onClick = "myPopUp()">
</body>
</html>
Mary Anne is offline
Reply With Quote
View Public Profile
 
Old 09-05-2008, 06:12 PM Re: Desperately seeking JavaScript help with school project...
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,528
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
the syntax for window.open is

window.open (URI,windowName,"menubar=1,resizable=1,width=px,height=px");

ALL the parameters are sent as a single CSV string (wrapped inside one set of quotes)
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 09-05-2008, 08:54 PM Re: Desperately seeking JavaScript help with school project...
Novice Talker

Posts: 8
Name: Mary
Trades: 0
Okay, so based on what you all said here and what I read in the W3 tutorial. I changed my function name but I still can't get this to work. I am really starting to get frustrated and I still have one project to go I javascript really this hard or is it because it is new or because I am just totally confused?

Any help is greatly appreciated as I am so lost, confused and frustrated that at this point I would drop the class if I could but it is too late for that. Thanks, Mary Anne

<html>
<head><title>Quiz 2</title>
<script language="javascript">

function myPopUp(){
var currentDate = new Date();
var specificDate = currentDate.getDay();
If(specificDate == 1){
window.open(http://www.ibm.com, quiz2,"width=400,height=200");
}
Else{
alert ("Today is not Monday. Please try again as soon as it is Monday.");
}
}
</script>
</head>
<body>
<input type="button" name="dispbutton" value="Display IBM" onClick = "myPopUp()">
</body>
</html>
Mary Anne is offline
Reply With Quote
View Public Profile
 
Old 09-06-2008, 03:58 AM Re: Desperately seeking JavaScript help with school project...
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,528
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
because your URI and window name fields are literals (actual values) rather than variables you need quotes around them (as you had initially)

Code:
window.open("http://www.ibm.com", "quiz2","width=400,height=200")
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 09-06-2008, 11:05 AM Re: Desperately seeking JavaScript help with school project...
Novice Talker

Posts: 8
Name: Mary
Trades: 0
I just wanted to let you know that I finally got the pop up box to work I was so happy about that! I guess my mistake was I wasn't adding my window name (quiz2) before the = window.open. I figure this out on the other project I was working on and then back tracked over to this one. It worked here to. YAY! But the rest of the statements still aren't working. So I am still puzzled with that one. Well, at least I am half way there on both projects! Anyway, thank you for helping me out so far.

html>
<head><title>Quiz 2</title>
<script language="javascript">
function myPopUp(){
var currentDate = new Date();
var specificDate = currentDate.getDay();
If(specificDate == 1){
quiz2=window.open("http://www.ibm.com", "quiz2","width=400,height=200");

}
Else{
document.write("Today is not Monday. Please try again as soon as it is Monday.");
}
}
</script>
</head>
<body>
<input type="button" name="dispbutton" value="Display IBM" onClick = "myPopUp()">
</body>
</html>
Mary Anne is offline
Reply With Quote
View Public Profile
 
Old 09-08-2008, 06:46 PM Re: Desperately seeking JavaScript help with school project...
vangogh's Avatar
Post Impressionist

Posts: 10,689
Name: Steven Bradley
Location: Boulder, Colorado
Trades: 0
Glad you got things working. Sorry I wasn't here over the weekend, but fortunately Chris was here to help you out.

What part are you working on now that isn't working. I'll be happy to help out more.
__________________
l Search Engine Friendly Web Design |
Please login or register to view this content. Registration is FREE

l Tips On Marketing, SEO, Design, and Development |
Please login or register to view this content. Registration is FREE

l
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
vangogh is offline
Reply With Quote
View Public Profile Visit vangogh's homepage!
 
Old 09-08-2008, 06:57 PM Re: Desperately seeking JavaScript help with school project...
wayfarer07's Avatar
Poo on You

Latest Blog Post:
Introducing WowWindow
Posts: 3,985
Name: Abel Mohler
Location: Asheville, North Carolina USA
Trades: 0
Chris works for 4 hours a day, sleeps for 2 hours a day, and is on Webmaster-Talk for the other 16 hours....
__________________
Join me on
Please login or register to view this content. Registration is FREE
wayfarer07 is offline
Reply With Quote
View Public Profile Visit wayfarer07's homepage!
 
Old 09-08-2008, 08:23 PM Re: Desperately seeking JavaScript help with school project...
vangogh's Avatar
Post Impressionist

Posts: 10,689
Name: Steven Bradley
Location: Boulder, Colorado
Trades: 0
He sleeps?
__________________
l Search Engine Friendly Web Design |
Please login or register to view this content. Registration is FREE

l Tips On Marketing, SEO, Design, and Development |
Please login or register to view this content. Registration is FREE

l
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
vangogh is offline
Reply With Quote
View Public Profile Visit vangogh's homepage!
 
Old 09-08-2008, 09:23 PM Re: Desperately seeking JavaScript help with school project...
Novice Talker

Posts: 8
Name: Mary
Trades: 0
Actually, just this evening, I finally figure out my mistake....so I have it all working now....

I had capitalize the if...else statement. Now I know what to watch when I type

So thank you again...I am sure I will be visiting here again and will definately be reading these boards. BTW, the W3 tutorial helped alot also, so thank you for directing me that way. I have that book marked.

Now back to visual basic,
Mary Anne
Mary Anne is offline
Reply With Quote
View Public Profile
 
Old 09-09-2008, 04:45 AM Re: Desperately seeking JavaScript help with school project...
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,528
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
The working hours is a bit of an over exaggeration as well
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 09-09-2008, 09:22 AM Re: Desperately seeking JavaScript help with school project...
wayfarer07's Avatar
Poo on You

Latest Blog Post:
Introducing WowWindow
Posts: 3,985
Name: Abel Mohler
Location: Asheville, North Carolina USA
Trades: 0
hmm... just realized my math is wrong... I left out 2 hours! Which means you're here for about 18-20 hours per day
__________________
Join me on
Please login or register to view this content. Registration is FREE
wayfarer07 is offline
Reply With Quote
View Public Profile Visit wayfarer07's homepage!
 
Reply     « Reply to Desperately seeking JavaScript help with school project...
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.40647 seconds with 12 queries