The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> function and function call
rjhmille
post May 22 2017, 02:18 PM
Post #1





Group: Members
Posts: 5
Joined: 22-May 17
Member No.: 26,413



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>
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
pandy
post May 22 2017, 04:08 PM
Post #2


Don't like donuts. Don't do MySpace.
********

Group: WDG Moderators
Posts: 17,765
Joined: 9-August 06
Member No.: 6



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?

User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 17th November 2017 - 11:33 PM