Reply
Problems with functions in math calculator
Old 02-18-2008, 02:09 PM Problems with functions in math calculator
Novice Talker

Posts: 8
Well I was writing a small jScript programs for fun. I wanted to have addition subtraction multipclication etc.
When I added the functions to be called by an html buton it did nothing.

Heres the code I used:
Code:
<html>
<head>
<title>Math calculator</title>
</head>
<body>
 
 
<script type="text/javascript">
 
//Math Calculator
//Code by Eddie Jones
 

function add(a,b,c)
{
var a = prompt("Enter first number", "Type number here");
var b = prompt("Enter second number", "Type number here");
var c = a+b;
document.write("Answer to addition problem is:"); document.write("<br>");
document.write("<br>");
document.write(c);
}

function multiply(d,e,f)
{
//getting variables to be used
var d = prompt("Enter first number", "Type number here");
var e = prompt("Enter second number, "Type number here");
 
//Answering the problem
var f = d*e;
 
//Multiplication answer
document.write("Answer to the mulplication problem is:"); document.write("<br>");
document.write("<br>")
document.write(f);
}

</script>
<input type="button" value="Addition" onclick="add()" > <br>
<br>
<input type="button" value="Multiplication" onclick="multiply()" > 
</body>
</html>
I named it math and saved it. (I used the // tags to remember what that part of the code did, I wrote the multiplication w/o functions and had the tags there, I just didnt bother to get rid of them)
Eddie12390 is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
Old 02-18-2008, 04:18 PM Re: Problems with functions in math calculator
chrishirst's Avatar
Super Moderator

Posts: 13,630
Location: Blackpool. UK
and your question is?
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
Indifference will be the downfall of mankind, but who cares?
Code Samples | People Counting System
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 02-18-2008, 08:02 PM Re: Problems with functions in math calculator
Novice Talker

Posts: 8
Oh sorry I cant believe I forgot that part :|

What did I do wrong in the code?
Eddie12390 is offline
Reply With Quote
View Public Profile
 
Old 02-19-2008, 05:13 AM Re: Problems with functions in math calculator
JeremyMiller's Avatar
Full-Time TeraTasker

Posts: 984
Name: Jeremy Miller
Location: Reno, NV
You were missing a closing double quote. You would have then found a few more issues and then come up with something like this:

HTML Code:
<html>
<head>
<title>Math calculator</title>
</head>
<body>


<script type="text/javascript">

//Math Calculator
//Code by Eddie Jones


function add(a,b,c)
{
var a = prompt("Enter first number", "Type number here");
var b = prompt("Enter second number", "Type number here");
var c = parseFloat(a)+parseFloat(b);
document.write("Answer to addition problem is:"); document.write("<br>");
document.write("<br>");
document.write(c);
}

function multiply(d,e,f)
{
//getting variables to be used
var d = prompt("Enter first number", "Type number here");
var e = prompt("Enter second number", "Type number here");

//Answering the problem
var f = parseFloat(d)*parseFloat(e);

//Multiplication answer
document.write("Answer to the mulplication problem is:"); document.write("<br>");
document.write("<br>")
document.write(f);
}

</script>
<input type="button" value="Addition" onclick="add(); return false;" > <br>
<br>
<input type="button" value="Multiplication" onclick="multiply(); return false;" >
</body>
</html>
__________________
Jeremy Miller - TeraTask Technologies, LLC
Content Farmer - Automated Posting for Content & Blog Sites
JeremyMiller is offline
Reply With Quote
View Public Profile Visit JeremyMiller's homepage!
 
Reply     « Reply to Problems with functions in math calculator
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.12499 seconds with 12 queries