Input String, return Number to test null?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • fingersnark
    New Member
    • Nov 2013
    • 1

    Input String, return Number to test null?

    I have a problem with my current code. I am trying to test the number for null and if it is, it will cancel my loop. It seems to cancel with the current way i have it, but i need the number to add up with the previous one each time it loops. How can i test for null to cancel, while getting my number to add up?

    Code:
    <html>
    <head>
    	<script type="text/javascript"> 
    			
    	function nameInput() {
    	var nameIn; 
    		nameIn = prompt("Enter the Employees name.");
    		
    		while(nameIn !== null &&(!isNaN(nameIn) || nameIn=="")) {
    		
    		
    		alert("Name cannot be Blank.\n must contain only LETTERS");
    		nameIn =prompt("Try again, Enter the employees name.");
    }	
    	
    	return nameIn;	
    }
    
    		function hoursInput() {
    	
    	 
    	var numIn=prompt("Enter the Hours worked for the Week");
    		
    		while(numIn !== null && (isNaN(numIn) || numIn=="")) {
    		
    		
    		alert("Hours cannot be Blank.\n must contain only NUMBERS.");
    		
    		numIn=prompt("Try again, Enter the Hours worked for the Week");
    	
    	}
    	
    	return numIn;	
    }
    
    </script>
    </head>
    <body>
    <script type="text/javascript">
    
    // DECLARATION
    var wage =10;
    var totalHours=0;
    var totalEarnings=0;
    var	Earnings;
    
    // PROCESSING LOOP
    var howMany = parseFloat(prompt(" How many employees are you inputting?", ""));
    
    for (var loopControl = 1; loopControl <= howMany; ++loopControl) {
    
    	var nameth=nameInput();
    		if(nameth==null){
    			break;
    }
    	
    	var hour=hoursInput();
    
    		if(hour==null){
    			break;
    }
    			
    			Earnings = hour * wage;
    			totalHours+=hour
    			totalEarnings+=Earnings;
    			
    			document.write("Name of employee. "   + nameth + "<br /br>");
    			document.write("This employee worked. "  + hour + "<br /br>" + "<br /br>");
    
    }
    
    // OUTPUT
    
    document.write("compiled Earnings is: " + totalEarnings + " " + "<br /br>");
    document.write("total amount of hours from all employees listed are: " + totalHours + " " + "<br /br>");
    
    </script>
    </body>
    </html>
Working...