Help - Search - Members - Calendar
Full Version: function and function call
HTMLHelp Forums > Programming > Client-side Scripting
rjhmille
I'm trying to make the header a function and call it below. but am having a hard time:

<!DOCTYPE html>
<html>
<head><!-- set up the head of the page-->
<meta charset="UTF-8" >
<title>Bar Chart</title> <!-- Give the page a title -->

</head> <!-- close the page head -->
<body> <!-- Open the page body -->
<script> <!-- design the loop in java script -->
{
<!--Ask the user for the hight of their chart -->
var upperLimit = parseInt(prompt("How high is your chart?", ""));
var symBol = prompt("What symbol do you want to use?","");

//document.getElementById("num").value = upperLimit;
//document.getElementById("symbol").value = symBol;

<!-- set the upper limit of the counter to the user input -->}
}
for(var counter = 1; counter <= upperLimit; counter++)

{

document.write("<p>"+symBol+" </p>");
<!-- output the chart to the height the user entered -->
}

</script><!-- close the java script -->

</body> <!-- close the body -->

</html>
pandy
Several things. The script isn't in HEAD. It's in BODY. There is no function and no function call either. But that doesn't matter. The below does.

You can't use HTML comments inside a script. You must use JS comments. // in front of a single line and /* and */ around a block.

You have curly braces where there shouldn't be any.

If you remove all of the above it boils down to the below and it runs.

CODE
var upperLimit = parseInt(prompt("How high is your chart?", ""));
var symBol = prompt("What symbol do you want to use?","");

//document.getElementById("num").value = upperLimit;
//document.getElementById("symbol").value = symBol;


for(var counter = 1; counter <= upperLimit; counter++)
{
   document.write("<p>"+symBol+" </p>");
}



Are you aware that document.write() will replace everything on the page?

This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2018 Invision Power Services, Inc.