/    Sign up×
Community /Pin to ProfileBookmark

cant get parsefloat to work

here is the code, it is supposed to calcualte the total of the books and display them but when displayed all i get is NAN (only works in ie). This is part of my course work so please help

<html>
<head>
<title>Arrays</title>
<script type=”text/javascript”>
function show_prompt(){
document.write(“<h2>Arrays</h2>”)
var book = new Array()
for (a = 0; a <= 10; a++){
book[a]=prompt(‘Enter book name’)
}
var price = new Array()
for (i = 0; i <= 10; i++){
price[i]=prompt(‘Enter price of item named :’+book[a]);
document.write(‘ <b>Name:</b> ‘+ book[a] + ” <b>Price:</b> “+price[i]+'<br/>’);
}
var total = parseFloat(price[i]);
document.write( ‘total:’ + total + ‘<br/>’)
}
</script>
</head>
<body onload = “show_prompt()”>
</head>
</html>

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@KorMay 17.2011 — <i>
</i>//...
var price = new Array();
[COLOR="Blue"]var total=0;[/COLOR]
for (i = 0; i &lt;= 10; i++){
price[i]=prompt('Enter price of item named :'+book[a]);
document.write(' &lt;b&gt;Name:&lt;/b&gt; '+ book[a] + " &lt;b&gt;Price:&lt;/b&gt; "+price[i]+'&lt;br/&gt;');
[COLOR="Blue"]total+=parseFloat(price[i]);[/COLOR]
}
document.write( 'total:' + total + '&lt;br/&gt;');
//...
Copy linkTweet thisAlerts:
@tyson642authorMay 17.2011 — thanks that works great now, i relaise where i went wrong
×

Success!

Help @tyson642 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.16,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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