/    Sign up×
Community /Pin to ProfileBookmark

Can’t get JavaScript output to display

The code below is for a page where a user types in three bowling scores and then clicks a button to display the average. I’ve done a very similar project in the past and used it to refamiliarize myself with JavaScript, as I haven’t been using it much lately. But anyway, here’s the code I typed up so far.

“`
<html>
<head>
<title></title>

<style type=”text/css”>

body {
background-color: lightblue;
color: blue;
font-family: arial;
text-align: center;
font-weight: bold;
}

#contentwrap {
border: 8px #FF0000 solid;
background-color: lightyellow;
border-radius: 20px;
padding: 15px;
width: 700px;
margin: 20px auto 0px auto;
}

#title {
font-size: 2.0em;
border-bottom: 8px #FF0000 double;
padding: 10px 0px 10px 0px;
}

#formdiv {
height: 400px;
padding-top: 10px;
}

.enterscore {
font-size: 1.5em;
margin-top: 20px;
}

#results {
font-size: 1.5em;
color: green;
}

</style>

<script src=”https://code.jquery.com/jquery-3.4.1.min.js” integrity=”sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=” crossorigin=”anonymous”></script>
<script src=”https://code.jquery.com/ui/1.12.1/jquery-ui.min.js” integrity=”sha256-VazP97ZCwtekAsvgPBSUwPFKdrwD3unUfSGVYrahUqU=” crossorigin=”anonymous”></script>

<script type=”text/javascript”>

$(document).ready(function(){

$(“#scorebutton”).on(“click”, function(){

var name = parseFloat( $(“#name”).val() );
var score1 = parseInt( $(“#score1”).val() );
var score2 = parseInt( $(“#score2”).val() );
var score3 = parseInt( $(“#score3”).val() );
var average = calcAvg(score1, score2, score3);
var msg = “<div>Bowler’s name is ” + name + “</div>”;
msg += “<div>Bowling average is ” + average + “</div>”;”

$(“#output”).html(msg);

});

});

</script>

</head>

<body>
<div id=”contentwrap”>

<div id=”title”>
Bowling Average Calculator
</div>

<div id=”formdiv”>

<form>

<div class=”enterscore”>Enter name of bowler</div>
<input type=”text” id=”bowlname” size=”20″ />

<div class=”enterscore”>Enter score 1</div>
<input type=”text” size=”20″ />

<div class=”enterscore”>Enter score 2</div>
<input type=”text” size=”20″ />

<div class=”enterscore”>Enter score 3</div>
<input type=”text” size=”20″ />

<div style=”margin-top: 10px;”>
<input type=”button” style=”border-radius: 8px;”
id=”scorebutton” value=”Calculate Average” onClick=”getAverage()”/>
</div>

</form>

<div id=”output” style = “margin-top:25px;”></div>

</div> <!– this closes contentwrap–>
</body>

</html>
“`

to post a comment
HTMLJavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@SempervivumDec 06.2021 — I did not test this but parseFloat is designated for parsing a number like 1248.75 and won't work on a person's name.

Omit it and check if the script works:

`var name = $("#name").val();</C>

BTW: Single backticks (probably created by the button <C>
&lt;/&gt;</C>) won't work reliably when posting code. You better use code tags: <C>your code here`
or triple backticks. I edited your posting accordingly.
Copy linkTweet thisAlerts:
@JIMBOYKELLYauthorDec 06.2021 — @Sempervivum#1640248 I just made the changes you showed me, but I still get no input
Copy linkTweet thisAlerts:
@SempervivumDec 07.2021 — You are calling a function calcAvg but it is not defined.
Copy linkTweet thisAlerts:
@daveyerwinDec 07.2021 — > @JIMBOYKELLY#1640245 I've done a very similar project in the past and used it to refamiliarize myself with JavaScript, as I haven't been using it much lately.

``<i>
</i>&lt;html&gt;
&lt;head&gt;
&lt;title&gt;&lt;/title&gt;
&lt;style type="text/css"&gt;
body {
background-color: lightblue;
color: blue;
font-family: arial;
text-align: center;
font-weight: bold;
}
#contentwrap {
border: 8px #FF0000 solid;
background-color: lightyellow;
border-radius: 20px;
padding: 15px;
width: 700px;
margin: 20px auto 0px auto;
}
#title {
font-size: 2.0em;
border-bottom: 8px #FF0000 double;
padding: 10px 0px 10px 0px;
}
#formdiv {
height: 400px;
padding-top: 10px;
}
.enterscore {
font-size: 1.5em;
margin-top: 20px;
}
#results {
font-size: 1.5em;
color: green;
}
&lt;/style&gt;
&lt;script src="https://code.jquery.com/jquery-3.4.1.min.js" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"&gt;&lt;/script&gt;
&lt;script src="https://code.jquery.com/ui/1.12.1/jquery-ui.min.js" integrity="sha256-VazP97ZCwtekAsvgPBSUwPFKdrwD3unUfSGVYrahUqU=" crossorigin="anonymous"&gt;&lt;/script&gt;

&lt;script type="text/javascript"&gt;
$(document).ready(function(){
$("#scorebutton").on("click", function(){
var name = $("#name").val();
var ins=document.forms[0].elements;
var score1 = parseInt( $(ins[1]).val() );
var score2 = parseInt( $(ins[2]).val() );
var score3 = parseInt( $(ins[3]).val() );
var average = (score1 + score2 + score3)/3;
var msg = "&lt;div&gt;Bowler's name is " + name + "&lt;/div&gt;";
msg += "&lt;div&gt;Bowling average is " + average + "&lt;/div&gt;";
$("#output").html(msg);

});
});
&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;div id="contentwrap"&gt;
&lt;div id="title"&gt;
Bowling Average Calculator
&lt;/div&gt;
&lt;div id="formdiv"&gt;
&lt;form&gt;
&lt;div class="enterscore"&gt;Enter name of bowler&lt;/div&gt;
&lt;input type="text" id="name" size="20" /&gt;
&lt;div class="enterscore"&gt;Enter score 1&lt;/div&gt;
&lt;input type="text" size="20" /&gt;
&lt;div class="enterscore"&gt;Enter score 2&lt;/div&gt;
&lt;input type="text" size="20" /&gt;
&lt;div class="enterscore"&gt;Enter score 3&lt;/div&gt;
&lt;input type="text" size="20" /&gt;
&lt;div style="margin-top: 10px;"&gt;
&lt;input type="button" style="border-radius: 8px;"
id="scorebutton" value="Calculate Average" /&gt;
&lt;/div&gt;
&lt;/form&gt;
&lt;div id="output" style = "margin-top:25px;"&gt;&lt;/div&gt;
&lt;/div&gt; &lt;!-- this closes contentwrap--&gt;
&lt;/body&gt;
&lt;/html&gt;

```
×

Success!

Help @JIMBOYKELLY spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.5,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...