SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: Stumped..

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Oct 2011
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Stumped..

    I'm currently working on a personal website, as a means of learning html/javascript. I'm trying to develop a 'simple' mathematical function that deals with calculations of knocked over cones for autocrossing, and cannot seem to figure out where I'm going wrong.

    I've stumbled upon this site and was wondering if you all would be willing to help me out.
    I'll attach the code in question below, hopefully you all will be able to help

    Section in the webpage where the function is called.
    Code:
    <form name ="Cone" onload="ConeCalculator(this.form)" id="page_content" style="width: 320px">
    </form>
    The javascript file is loaded up in the script section through
    Code:
    <script type="text/javascript" src="media/javascript/ConeCalculator.js">

    Here is the code inside the javascript file. The idea in mind is to randomly generate a number (minutes.seconds) as well as a random number of cones that have been knocked over. The objective of the user is t o correctly add up the correct time for the amount of cones knocked over. I've yet to get to adding in the input object for the user, because i cannot get the random numbers to display at all. Here is the current code i've created
    Code:
    function ConeCalculator(Cone)
    {
    
    var Minutes;
    var Seconds;
    var Cones;
    
    document.writeln("<table border =\"0\">");
    document.writeln("<caption>Cone Calculations</caption></tr>");
    
    
    for (var i = 0; i <= 1; i++)
    	{
    	Minutes = Math.floor( 1 + math.random() * 10);
    	Seconds = Math.floor( 1 + Math.random() * 60);
    	document.writeln("<td>" + "Your car finished in " + Minutes + "." + Seconds + "." + "</td></tr>");
    	Cones = Math.floor( 1 + math.random() * 20);
    	document.writeln("<td><tr>" + "Cones knocked over" + Cones + "</td></tr>");
    	}
    	
    }
    The idea here is to have all of this generated in a function, then inserted into the form created on the page. None of the javascript debuggers I know of seem to help (firebug, i.e debugger and chrome's debugger). No errors are being logged, yet nothing happens when the page loads. I've attempted adding a button to trigger the function but to no avail. Any help would be greatly appreciated!

  2. #2
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,784
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Your function contains document.writeln which can only run before the page finishes loading but the function is only called after the page finishes loading.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  3. #3
    Non-Member
    Join Date
    Apr 2011
    Location
    no fixed address
    Posts
    851
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by felgall View Post
    Your function contains document.writeln which can only run before the page finishes loading but the function is only called after the page finishes loading.
    That's not correct. I've used document.write and document.writeln after a page finishes loading and the output is written to a new page as it is supposed to.


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
  •