to set the value of the textbox back to 0

I have the counters worhing but am unable to reset them

Page 1 of 1

3 Replies - 675 Views - Last Post: 10 November 2009 - 07:01 PM

#1 goddesszilla  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 10-November 09

to set the value of the textbox back to 0

Posted 10 November 2009 - 01:29 AM

The assignment is clearly stated at the top of the first page. Its due tomarrow, I just got my counters working this afternoon and Im sure its a simple syntax error because the error console in fire fox is not finding an error, yet my texbox does not reset. thank you to anyone willing to help.
<html>
<!--1.	. Save the file as TwoDiceRolls_v2.htm.  Read all exercise assignments to understand what is being asked; you will		--> 
<!--combine these into ONE webpage. COPY and use the same code here from the above problem  (#1, 11.8) for this 2nd assignment	-->
<!--and then add the following:																								   -->
<!--A text box counter (ctr) that tracks how many times the dice has been "rolled."  A second text box ctr to keep track of	   --> 
<!--how many times DOUBLES have been "rolled". A button that CLEARS out and RESETS all textboxes to zero AND sets the dice back   --> 
<!--to show the number 1 on both die (as shown when the page first loads in Problem #1, above).Place your function(s) into a	  -->
<!--library "Functions_v2.js" and reference it using the 'srcattribute assigned to the file name inside your htm file.  Place	 -->
<!--your js file inside your homework floder.																					 -->
<!--TwoDiceRolls_v2.htm																							 XXXXXXXXXXXXX -->
<!-- ============================================================================================================================ -->
 <head>
  <title> Die Rolls </title> 
   
   <script type="text/javascript"
	src="FunJava.js">
	</script> 
	<script type="text/javascript"
	src="random.js">
  </script> 
 </head>
 
 <body>
  <div style="text-align:center">
   <p>
   <img id="dieOne" alt="die image" 
	src="http://www.dave-reed.com/book/Images/die1.gif" />
   <img id="dieTwo" alt="die image" 
	src="http://www.dave-reed.com/book/Images/die1.gif" />  
   </p> 
   
   <p> 
   <input type="button" value="Click to Roll" onclick="RollOne()" />
   </p>
	
   <p>
   You have rolled <input type="textbox" id="NumRolls" size="10" value="0" /> times
   and gotten <input type="textbox" id="NumDubs" size="10" value="0" /> doubles.
   </p>
   
   <p>
   <input type="button" value="Start over" onclick="clear()" />
   </p>
   
   </div>
   
  </body> 
 </html>

// PAGE 2THE .js FILE

// FunJava.js XXXXXi XXXXXXXX

function RollOne() 
	{
	var num, doubleCount, numrolls, rollone;
	
	 
   rollone = RandomInt(1, 6);
	
	RollTwo(rollone);
	
	if (rollone == 1) { 
	 document.getElementById("dieOne").src = 
	 "http://www.dave-reed.com/book/Images/die1.gif";
	} 
	else if (rollone == 2) { 
	 document.getElementById("dieOne").src =
	 "http://www.dave-reed.com/book/Images/die2.gif";
	} 
	else if (rollone == 3) { 
	 document.getElementById("dieOne").src =
	 "http://www.dave-reed.com/book/Images/die3.gif";
	}
	else if (rollone == 4) { 
	 document.getElementById("dieOne").src =
	 "http://www.dave-reed.com/book/Images/die4.gif";
	}
	else if (rollone == 5) { 
	 document.getElementById("dieOne").src =
	 "http://www.dave-reed.com/book/Images/die5.gif";
	}
	else { 
	 document.getElementById("dieOne").src =
	 "http://www.dave-reed.com/book/Images/die6.gif";
	}
	
	}
 function RollTwo(rollone) 
	 // Assumes : die images are in dave-reed.com/book/Images
	 // Results : displays a randomly selected image of a 6-sided die
   {
	rolltwo = RandomInt(1, 6);
	
	if (rolltwo == 1) { 
	 document.getElementById("dieTwo").src = 
	 "http://www.dave-reed.com/book/Images/diel.gif";
	} 
	else if (rolltwo == 2) { 
	 document.getElementById("dieTwo").src =
	 "http://www.dave-reed.com/book/Images/die2.gif";
	} 
	else if (rolltwo == 3) { 
	 document.getElementById("dieTwo").src =
	 "http://www.dave-reed.com/book/Images/die3.gif";
	}
	else if (rolltwo == 4) { 
	 document.getElementById("dieTwo").src =
	 "http://www.dave-reed.com/book/Images/die4.gif";
	}
	else if (rolltwo == 5) { 
	 document.getElementById("dieTwo").src =
	 "http://www.dave-reed.com/book/Images/die5.gif";
	}
	else { 
	 document.getElementById("dieTwo").src =
	 "http://www.dave-reed.com/book/Images/die6.gif";
	}
	if (rollone > 0) {
	document.getElementById("NumRolls").value = parseFloat(document.getElementById("NumRolls").value) +1;
	}	 
	if (rollone == rolltwo){
	document.getElementById("NumDubs").value = parseFloat(document.getElementById("Numdubs").value) +1;
	}
	
	
	}
	function clear()
	 
	  
	{
	 var num1, num2;
	 num1 = 0
	 num2 = 0
	 document.getElementById("NumRolls").value = parseFloat("num1")
	 document.getElementById("NumDubs").value = parseFloat("num2")
	 }
// PAGE 3
// File: random.js
// Author: Dave Reed
//
// This file contains several routines for generating random values.
// Source code is available at http://dave-reed.com/book
//////////////////////////////////////////////////////////////////////

function RandomNum(low, high)
// Given : low <= high
// Returns : a random number in the range [low, high)
{
	return Math.random()*(high-low) + low;
}

function RandomInt(low, high)
// Given : low <= high
// Returns : a random integer in the range [low, high]
{
	return Math.floor(Math.random()*(high-low+1)) + low;
}

This post has been edited by goddesszilla: 10 November 2009 - 01:41 AM


Is This A Good Question/Topic? 0
  • +

Replies To: to set the value of the textbox back to 0

#2 ecuscotty  Icon User is offline

  • New D.I.C Head

Reputation: 5
  • View blog
  • Posts: 40
  • Joined: 14-October 09

Re: to set the value of the textbox back to 0

Posted 10 November 2009 - 07:10 AM

Your missing a couple of ";" in your clear function.

	 num1 = 0
	 num2 = 0



... should be ...

	 num1 = 0;
	 num2 = 0;



Good luck.
Was This Post Helpful? 0
  • +
  • -

#3 goddesszilla  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 10-November 09

Re: to set the value of the textbox back to 0

Posted 10 November 2009 - 10:36 AM

ok, I fixed that, but they still dont clear.
Was This Post Helpful? 0
  • +
  • -

#4 forest51690  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 58
  • View blog
  • Posts: 340
  • Joined: 20-March 09

Re: to set the value of the textbox back to 0

Posted 10 November 2009 - 07:01 PM

Here's your error:

document.getElementById("NumRolls").value = parseFloat("num1")
document.getElementById("NumDubs").value = parseFloat("num2")



Your variables are in quotes, so they are treated as strings, not variables
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1