help me with my final exam pls, i need to know where to find the error with this code using html with |
help me with my final exam pls, i need to know where to find the error with this code using html with |
karlamd |
Apr 12 2015, 05:01 AM
Post
#1
|
Group: Members Posts: 2 Joined: 12-April 15 Member No.: 22,482 |
<html>
<body> <script type="text/javascript"> do{ function zodiac(){ var name=prompt("enter name"," "); var month=prompt("enter birth month"," "); var date=prompt("enter birth date"," "); switch(month) { case "January": case "january": case "jan": if(date >= 21); { var Ans="Hi "+ name + ", " +"your birthday is " + month + " " + date + ". Your zodiac sign is Aquarius"; alert(Ans); } else; { var Ans="Hi "+ name + ", " +"your birthday is " + month + " " + date + ". Your zodiac sign is Pisces"; alert(Ans); } break; } } zodiac(); var Ans=prompt("try again?"," "); } while(Ans=="Yes"||Ans=="yes"); </script> </body> </html> |
karlamd |
Apr 12 2015, 05:02 AM
Post
#2
|
Group: Members Posts: 2 Joined: 12-April 15 Member No.: 22,482 |
and if ever you have a code for this zodiac sign with birth dateand birth month please. i will much appreciate it.thank you
|
Frederiek |
Apr 12 2015, 07:55 AM
Post
#3
|
Programming Fanatic Group: Members Posts: 5,146 Joined: 23-August 06 From: Europe Member No.: 9 |
|
Christian J |
Apr 12 2015, 07:58 AM
Post
#4
|
. Group: WDG Moderators Posts: 9,656 Joined: 10-August 06 Member No.: 7 |
There shouldn't be any semicolons after the IF and ELSE statements.
BTW I'm not sure if the SWITCH statement is used in a proper/efficient way. In any case you might avoid testing both "January" and "january" by using e.g. the toLowerCase() function: http://www.quirksmode.org/js/strings.html#tocase It can be confusing for the user to type Yes in the final prompt box (I clicked the Cancel button which didn't work). Use a confirm box instead, then the user can click OK or Cancel without having to type anything. Also using a DO/WHILE loop seems like a strange solution, I'd rather call function zodiac() again if the user clicked Yes/OK. and if ever you have a code for this zodiac sign with birth dateand birth month please. i will much appreciate it.thank you Here they are in Unicode: http://www.unicode.org/charts/PDF/U2600.pdf (no idea about the dates). To use them in javascript, I think you can insert a "\u" before the code number, like this for Taurus: CODE alert('\u2649'); |
Christian J |
Apr 12 2015, 08:43 AM
Post
#5
|
. Group: WDG Moderators Posts: 9,656 Joined: 10-August 06 Member No.: 7 |
And if this for an exam you should probably put a Doctype at the very beginning of the page: http://htmlhelp.com/faq/html/basics.html#doctype
Also a valid HTML page needs a HEAD section: http://www.w3.org/TR/html4/struct/global.html#h-7.1 |
Lo-Fi Version | Time is now: 24th April 2024 - 04:25 AM |