Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



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

Posts: 8
Trades: 0
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
 
 
Register now for full access!
Old 02-18-2008, 05:18 PM Re: Problems with functions in math calculator
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,528
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
and your question is?
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 02-18-2008, 09:02 PM Re: Problems with functions in math calculator
Novice Talker

Posts: 8
Trades: 0
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, 06:13 AM Re: Problems with functions in math calculator
JeremyMiller's Avatar
WT Moderator

Posts: 1,712
Name: Jeremy Miller
Location: Las Vegas, NV
Trades: 0
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

Please login or register to view this content. Registration is FREE
JeremyMiller is offline
Reply With Quote
View Public Profile Visit JeremyMiller's homepage!
 
Reply     « Reply to Problems with functions in math calculator
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB 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.44956 seconds with 12 queries