var vergi=function taxCalculator(){

    var income=5 
    var taxRate=0.04;
    var totalTax=income*taxRate;
    return  totalTax ;

    document.write( '<p> totalTax </p>')
}

vergi()

________________________________________________________________   



<body>

<header>
    <h1>Sadelewtirilmiw vergi hesablayicisi</h1>
</header>

<form method="post">
    Yekun Geliriniz <input type="text" name='gelir' id='gelir'>
    <input type="button" name='hesabla' id='hesabla' value='hesabla' onClick="vergi()">
</form>
<h2></h2>
<p></p>



</body>

Recommended Answers

All 3 Replies

Member Avatar for iamthwee

Do you know the basics? Totaltax is a variable not a string so you don't surround it with quote marks.

e.g.

document.write( '<p> totalTax </p>')

should be

document.write( '<p>' + totalTax + '</p>');

Member Avatar for DaniWebUser_1

You have quite a few problems with your document. I just went ahead and wrote a new html document with a script based on what I believe you wanted to do. Here it is:

<!DOCTYPE html>

<html>

<head>

<title>My Tax Calculator</title>

<style>



    #totalTaxDisplay {

      height:20px;
      width:120px;
      border:black 2px solid;
      overflow:hidden;

    }



</style>

</head>

<body>

<header> <h1>Sadelewtirilmiw vergi hesablayicisi</h1> </header>

<form method="post">

Yekun Geliriniz <input type="text" name="gelir" id="gelir">
                <input type="button" name="hesabla" id="hesabla"    
                value="hesabla" onclick="taxCalculator()">

</form>

<h2>Here is your tax:</h2>

<p id="totalTaxDisplay"></p>

<script>

function taxCalculator() {
    var income = document.getElementById("gelir").value; 
    var taxRate = 0.04;
    var totalTax = Number(income*taxRate);
    document.getElementById("totalTaxDisplay").innerHTML = totalTax;
}

</script>

</body>

</html>

I added a little CSS styling inside the <style> tags. That was just to make it look a little better. I'm not going to go over all of the problems you had here. You can look over the html and the javascript here and see what some of your problems were. I will mention a few things, however. For one, you must always use semi-colons at the end of a javascript line of code. Also, all inline events like your onclick event in the html are always all lowercase. You wrote it as onClick in camel case.

Also, javascript functions like document.write(), input(), and alert() are great learning tools. But, you shouldn't use them once you start getting a good grasp of the language and are ready to start writing real code for real situations. There are better alternative techniques that will do the same thing. Alert() is pretty annoying for a lot of people, and document.write() will actually erase everything you had on your page before and replace it with your document.write() content. I hope this was able to help you and I hope you keep learning. A really great free site for learning web development is www.w3schools.com.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.