Results 1 to 6 of 6

Thread: Not getting proper output for Return Statement

  1. #1
    Join Date
    Aug 2006
    Posts
    235

    Not getting proper output for Return Statement

    I have written the following code for the random number between 1 - 100. The following is the code that I have used :
    Code:
    function newGetal(){
    	var g = Math.random()*100;
    	g = Math.round(g);
    	return g;
    }
    var getal = newGetal();
    This program should generate a new random number between 1 - 100 every time the function is called. The problem is that it generates a new number but the number in "getal" stays the same. I think that something is wrong in the code. Anyone can help to get proper output for Return Statement..?? Please help me soon..!!
    3.2 (northwood)
    2gig ram
    ATI AIW X800xt 256mb
    Gigabyte GA-8knxp 875p Chipset
    Optiwrite 8X DVD Burner
    Win XP PRO Sp2 (Works Perfectly)
    2 SATA Raptor 74gig Raid 0
    2 7200 IDE 320gig HD

  2. #2
    Join Date
    Nov 2008
    Posts
    996

    Re: Not getting proper output for Return Statement

    You have mentioned that the program is generating a new number but the number in "getal" stays the same. So, it means that the var getal gets assigned a value when you do var getal = newGetal(); I think that the problem is occurring because the page is remaining the same and not loading again. You can try the following code :
    HTML Code:
    <html lang="en">
      <head>
        <title>Test</title>
    <script type="text/javascript">
    function newGetal(){
    	var g = Math.random()*100;
    	g = Math.round(g);
    	return g;
    }
    var getal = newGetal();
    </script>
      </head>
      <body>
        <div id="testing"></div>
         <a onclick="document.getElementById('testing').innerHTML = newGetal();return false;" href="#">Random Numbers</a>
      </body>
    </html>

  3. #3
    Join Date
    Aug 2006
    Posts
    235

    Re: Not getting proper output for Return Statement

    Thanks for trying to solve my problem. But that didn't fixed my problem.
    Code:
    <input type="reset" class="button" id="reset" value="Open New" onclick="newGetal()" />
    I have tried that but not able to solve my query. So please help me..!!
    3.2 (northwood)
    2gig ram
    ATI AIW X800xt 256mb
    Gigabyte GA-8knxp 875p Chipset
    Optiwrite 8X DVD Burner
    Win XP PRO Sp2 (Works Perfectly)
    2 SATA Raptor 74gig Raid 0
    2 7200 IDE 320gig HD

  4. #4
    Join Date
    May 2008
    Posts
    2,389

    Re: Not getting proper output for Return Statement

    The function that you have given is called through an onclick event. It should work properly. You might have made the mistake somewhere else. Otherwise you might are missing something..!!! It would be better if you provide the complete code that you have made.!!

  5. #5
    Join Date
    Aug 2006
    Posts
    235

    Re: Not getting proper output for Return Statement

    The following is my complete code :

    HTML Code:
    <html xmlns="http://www.javascript.org/2001/xhtml">
    <head>
    <title>Getting Started</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <link rel="stylesheet" type="text/css" href="getstart.css" />
    <script type="text/javascript">
    var teller = 0;
    
    function newGetal(){
    	teller = 0;
    	var g = Math.random()*100;
    	g = Math.round(g);
    	return g;
    }
    var getal = newGetal();
    
    
    function getlen(){
    	var word = document.getElementById("word");
    	var greek = document.getElementById("greek").value;
    	teller++;
    	
    	if(greek> getal){
    		word.value = "This value is greater."
    	}
    	
    	if(greek< getal){
    		word.value = "This value is smaller."
    	}
    	
    	if(greek== getal){
    		word.value = "CORRECT! You have got "+teller+" keep going.!"
    	}
    }
    </script>
    </head>
    <body>
    <div id="wrapper">
    <form action="">
    	<fieldset>
    		<legend>Gokwerk</legend>
    		<div id="text">
    			<p>Do you have enough knowledge.?</p>
    		</div>
    		<div class="field">
    			<input type="text" id="greek" name="greek" size="3" maxlength="3" />
    			<label for="greek">So you know that.!!</label>
    		</div>
    		<div class="field">
    			<input type="text" id="word" name="word" size="74" />
    			<label for="word">word</label>
    		</div>
    		<input type="button" class="button" value="Gokken" onclick="gokken()" />
    		<input type="reset" class="button" id="reset" value="Open New" onclick="newGetal()" />
    		
    	</fieldset>
    </form>
    </div>
    </body>
    </html>
    3.2 (northwood)
    2gig ram
    ATI AIW X800xt 256mb
    Gigabyte GA-8knxp 875p Chipset
    Optiwrite 8X DVD Burner
    Win XP PRO Sp2 (Works Perfectly)
    2 SATA Raptor 74gig Raid 0
    2 7200 IDE 320gig HD

  6. #6
    Join Date
    May 2008
    Posts
    2,389

    Re: Not getting proper output for Return Statement

    The coding that I have stated below should help to fix your problem. Here is the coding :
    HTML Code:
    <html xmlns="http://www.javascript.org/2001/xhtml">
    <head>
    <title>Getting Started</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <link rel="stylesheet" type="text/css" href="gokwerk.css" />
    <script type="text/javascript">
    var teller = 0;
    
    function newGetal(){
    	teller = 0;
    	var g = Math.random()*100;
    	g = Math.round(g);
    	return g;
    }
    var getal = newGetal();
    
    
    function getlen(){
    	var word = document.getElementById("word");
    	var greek = document.getElementById("greek").value;
    	teller++;
    	
    	if(greek > getal){
    		word.value = "This value is greater."
    	}
    	
    	if(greek < getal){
    		word.value = "This value is smaller."
    	}
    	
    	if(greek == getal){
    		word.value = "CORRECT! You have got "+teller+" keep going.!"
    	}
    }
    </script>
    </head>
    <body>
    <div id="wrapper">
    <form action="">
    	<fieldset>
    		<legend>Gokwerk</legend>
    		<div id="text">
    			<p>Do you have enough knowledge.?</p>
    		</div>
    		<div class="field">
    			<input type="text" id="greek" name="greek" size="2" maxlength="2" />
    			<label for="greek">So you know that.!!</label>
    		</div>
    		<div class="field">
    			<input type="text" id="word" name="word" size="70" />
    			<label for="word">Word</label>
    		</div>
    		<input type="button" class="button" value="Gokken" onclick="gokken()" />
    		<input type="reset" class="button" id="reset" value="Open New" onclick="window.getal = newGetal()" />
    		
    	</fieldset>
    </form>
    </div>
    </body>
    </html>

Similar Threads

  1. Replies: 6
    Last Post: 22-01-2012, 10:20 AM
  2. Canon printer is not giving proper output.
    By Dropper in forum Hardware Peripherals
    Replies: 5
    Last Post: 04-05-2011, 06:25 AM
  3. Dragon Age 2 with no proper audio output
    By Jigya L. in forum Video Games
    Replies: 6
    Last Post: 13-03-2011, 01:28 PM
  4. Macbook Air: visual output is not proper with windows 7
    By marble12 in forum Portable Devices
    Replies: 5
    Last Post: 04-01-2011, 04:22 PM
  5. Replies: 3
    Last Post: 16-11-2009, 12:29 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,751,830,183.72070 seconds with 16 queries