var vergi=function taxCalculator(){

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

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




    <h1>Sadelewtirilmiw vergi hesablayicisi</h1>

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


Edited by Fuad_1

2 Years
Discussion Span
Last Post by DaniUserJS

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

Edited by iamthwee



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

should be

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


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>



<title>My Tax Calculator</title>


    #totalTaxDisplay {

      border:black 2px solid;





<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()">


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

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


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




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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.