6 Replies - 1190 Views - Last Post: 23 January 2009 - 05:58 AM

#1 rttlsnake  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 22
  • Joined: 08-February 08

javascript error. Can't find. Help!

Post icon  Posted 18 January 2009 - 05:00 PM

I have 2 assignments and I can figure out what or why the javascript section on either one is not working. If someone could look at my code and tell me where I am going wrong or point to the area of code. THanks for any help you can give.

<html>
 
<head>
<title>Event</title>
</head>
 
<body>
 
<script type="text/javascript">
<!-- HIDE FROM INCOMPATIBLE BROWSERS
// STOP HIDING FROM INCOMPATIBLE BROWSERS -->
 
var myWedding = "Jack & Jill Wedding";
var guests = 300;
var costPerGuest = 55 * guests;
var limo = 7;
var costPerLimo = 100 * limo;
var totalCost = costPerGuest + costPerLimo + musicCost + flowerCost + barCost;
var liveMusic = true;
Var musicCost;
(liveMusic == true) ? musicCost = 500 : musicCost = 0;
var flowers = true;
var flowerCost;
(flowers == true) ? flowerCost = 300 : flowerCost = 0;
var openBar= true;
Var barCost;
(openBar == true) ? barCost = 30 * guests : barCost = 0;

document.write("<p>Number of guests: " + guests + ".</p>");
document.write("<p>Cost per guest: " + costPerGuest + ".</p>");
document.write("<p>Limos needed: " + limo + ".</p>");
document.write("<p>Cost per Limo: " + costPerLimo + ".</p>");
document.write("<p>Live Music: $" + musicCost + ".</p>");
document.write("<p>Flowers: $" + flowerCost + ".</p>");
document.write("<p>Open bar: $" + barCost + ".</p>");
document.write("<p>Total cost for " + myWedding + " is: $" + totalCost + ".</p>");
</script>
 
</body> 
</html>



2nd assignment
<!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
 
<head>

<title>Exit Row Requirements</title>
<meta http-equiv="content-type" content="text/html;
	 charset=iso-8859-1" />

</head>
 
<body>
 
<script type="text/javasscript">
/* <![CDATA[ */
if (!window.confirm("Are you under 15 years old?"))
	document.write("<p>By federal law, children under age 15
		  may not sit in emergency exit rows.</p>");
else if (!window.confirm("Are you capable of lifting 50 or more pounds?"))
 	document.write("<p>You must be able to lift 50 or more
		  pounds to sit in an exit row.</p>");
else if (!window.confirm("Are you willing to assist the crew in
	  the event of an emergency?"))
 	document.write("<p>To sit in an exit row, you must be
		  willing to assist the crew in the event of an 
		  emergency.</p>");
else
 	document.write("<p>You meet the criteria for sitting in an
		  exit row.</p>");
/* ]]> */
</script>

<!-- W3C validated icon -->
<p>
<a href="http://validator.w3.org/check?uri=referer"><img
 	src="http://www.w3.org/Icons/valid-xhtml10-blue"
		alt="Valid XHTML 1.0 Strict" height="31" width="88" /></a>
</p>
 
</body>
</html>



Is This A Good Question/Topic? 0
  • +

Replies To: javascript error. Can't find. Help!

#2 Christopher Elison  Icon User is offline

  • D.I.C Head

Reputation: 39
  • View blog
  • Posts: 230
  • Joined: 29-December 08

Re: javascript error. Can't find. Help!

Posted 18 January 2009 - 05:03 PM

In assignment 1, I can immediately notice you mistyped 'var' as 'Var' twice (case of the 'v').
Was This Post Helpful? 0
  • +
  • -

#3 JMRKER  Icon User is offline

  • D.I.C Addict

Reputation: 128
  • View blog
  • Posts: 826
  • Joined: 25-October 08

Re: javascript error. Can't find. Help!

Posted 18 January 2009 - 05:05 PM

Problem #1
var totalCost = costPerGuest + costPerLimo + musicCost + flowerCost + barCost;
var liveMusic = true;
Var musicCost;


Hard to get valid results with variables that have yet to be initialized.

Haven't looked at problem #2 yet.
Was This Post Helpful? 0
  • +
  • -

#4 Christopher Elison  Icon User is offline

  • D.I.C Head

Reputation: 39
  • View blog
  • Posts: 230
  • Joined: 29-December 08

Re: javascript error. Can't find. Help!

Posted 18 January 2009 - 05:09 PM

I now get:

Number of guests: 300.

Cost per guest: 16500.

Limos needed: 7.

Cost per Limo: 700.

Live Music: $500.

Flowers: $300.

Open bar: $9000.

Total cost for Jack & Jill Wedding is: $27000.



After moving var totalCost = costPerGuest + costPerLimo + musicCost + flowerCost + barCost; to just before the first document.write.
Was This Post Helpful? 0
  • +
  • -

#5 rttlsnake  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 22
  • Joined: 08-February 08

Re: javascript error. Can't find. Help!

Posted 18 January 2009 - 05:10 PM

Thank you guys I got assignment 1 to work properly!
Was This Post Helpful? 0
  • +
  • -

#6 BetaWar  Icon User is online

  • #include "soul.h"
  • member icon

Reputation: 1134
  • View blog
  • Posts: 7,094
  • Joined: 07-September 06

Re: javascript error. Can't find. Help!

Posted 18 January 2009 - 05:12 PM

<edit>
Grrr, walk away for 5 minutes and tere are 5 replies...
</edit>

For the first one you have 2 problems. One of which is you have Var instead of var in there a couple of times. THe other is that you are creating and setting the total cost variable before all of the variables that it uses are set.

Here is the final code:
<script>
var myWedding = "Jack & Jill Wedding";
var guests = 300;
var costPerGuest = 55 * guests;
var limo = 7;
var costPerLimo = 100 * limo;
var liveMusic = true;
var musicCost;
musicCost = (liveMusic == true) ? 500 : 0;
var flowers = true;
var flowerCost;
flowerCost = (flowers == true) ? 300 : 0;
var openBar= true;
var barCost;
barCost = (openBar == true) ? 30 * guests : 0;
var totalCost = costPerGuest + costPerLimo + musicCost + flowerCost + barCost;

document.write("<p>Number of guests: " + guests + ".</p>");
document.write("<p>Cost per guest: " + costPerGuest + ".</p>");
document.write("<p>Limos needed: " + limo + ".</p>");
document.write("<p>Cost per Limo: " + costPerLimo + ".</p>");
document.write("<p>Live Music: $" + musicCost + ".</p>");
document.write("<p>Flowers: $" + flowerCost + ".</p>");
document.write("<p>Open bar: $" + barCost + ".</p>");
document.write("<p>Total cost for " + myWedding + " is: $" + totalCost + ".</p>");
</script>


I am going to look at the second one now...
Was This Post Helpful? 0
  • +
  • -

#7 webwritersgroup  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 9
  • Joined: 14-January 09

Re: javascript error. Can't find. Help!

Posted 23 January 2009 - 05:58 AM

View Postrttlsnake, on 18 Jan, 2009 - 06:00 PM, said:

I have 2 assignments and I can figure out what or why the javascript section on either one is not working. If someone could look at my code and tell me where I am going wrong or point to the area of code. THanks for any help you can give.

<html>
 
<head>
<title>Event</title>
</head>
 
<body>
 
<script type="text/javascript">
<!-- HIDE FROM INCOMPATIBLE BROWSERS
// STOP HIDING FROM INCOMPATIBLE BROWSERS -->
 
var myWedding = "Jack & Jill Wedding";
var guests = 300;
var costPerGuest = 55 * guests;
var limo = 7;
var costPerLimo = 100 * limo;
var totalCost = costPerGuest + costPerLimo + musicCost + flowerCost + barCost;
var liveMusic = true;
Var musicCost;
(liveMusic == true) ? musicCost = 500 : musicCost = 0;
var flowers = true;
var flowerCost;
(flowers == true) ? flowerCost = 300 : flowerCost = 0;
var openBar= true;
Var barCost;
(openBar == true) ? barCost = 30 * guests : barCost = 0;

document.write("<p>Number of guests: " + guests + ".</p>");
document.write("<p>Cost per guest: " + costPerGuest + ".</p>");
document.write("<p>Limos needed: " + limo + ".</p>");
document.write("<p>Cost per Limo: " + costPerLimo + ".</p>");
document.write("<p>Live Music: $" + musicCost + ".</p>");
document.write("<p>Flowers: $" + flowerCost + ".</p>");
document.write("<p>Open bar: $" + barCost + ".</p>");
document.write("<p>Total cost for " + myWedding + " is: $" + totalCost + ".</p>");
</script>
 
</body> 
</html>



2nd assignment
<!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
 
<head>

<title>Exit Row Requirements</title>
<meta http-equiv="content-type" content="text/html;
	 charset=iso-8859-1" />

</head>
 
<body>
 
<script type="text/javasscript">
/* <![CDATA[ */
if (!window.confirm("Are you under 15 years old?"))
	document.write("<p>By federal law, children under age 15
		  may not sit in emergency exit rows.</p>");
else if (!window.confirm("Are you capable of lifting 50 or more pounds?"))
 	document.write("<p>You must be able to lift 50 or more
		  pounds to sit in an exit row.</p>");
else if (!window.confirm("Are you willing to assist the crew in
	  the event of an emergency?"))
 	document.write("<p>To sit in an exit row, you must be
		  willing to assist the crew in the event of an 
		  emergency.</p>");
else
 	document.write("<p>You meet the criteria for sitting in an
		  exit row.</p>");
/* ]]> */
</script>

<!-- W3C validated icon -->
<p>
<a href="http://validator.w3.org/check?uri=referer"><img
 	src="http://www.w3.org/Icons/valid-xhtml10-blue"
		alt="Valid XHTML 1.0 Strict" height="31" width="88" /></a>
</p>
 
</body>
</html>




For starters (assignment 2), you misspelled javascript...

<script type="text/javasscript">

Also, I was getting unterminated string errors. After I put each document.write on one line (along with the confirm statements) it worked for me.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1