I am Unable to get output in this JS before loop termination

Viewed 54

i want to get my output after every iteration of loop but it gives me output when loop is terminated.i am unable to get why am facing this issue as am newbie to JS. after i press N to terminate loop n prompt get closed i get output on webscreen.maybe i look stupid but i am not able to solve it own my own n PS vote Postive for my question as i am geting question ban.

 <script type="text/javascript">
    do{
    var value1=prompt("enter 1st number::"," ");
    var value2=prompt("enter 2nd number::"," ");
    var op=prompt("Enter operator from(+,-,*,/,%age,average):");
    if (op=="+")
    {
        var result=parseInt(value1)+parseInt(value2);
        document.write("addition result is ="+result );
        document.write("<br/>");
    }
    else if(op=="-")
        
    {
        var result=parseInt(value1)-parseInt(value2);
        document.write("substraction result is ="+result );
    document.write("<br/>");
    }
    else if (op=="*")
    
        
    {
        var result=parseInt(value1)*parseInt(value2);
        document.write("multiplication  result is ="+result);
    document.write("<br/>");
    }
    else if (op=="/")
    
       
    {
        var result=parseInt(value1)/parseInt(value2);
        document.write("division  result is ="+result );
        document.write("<br/>");
    }
    else if (op=="%age")
    
       
    {
        var result=(parseInt(value1)/parseInt(value2))*100;
        document.write("percentage of value1 with value 2  is ="+result );
        document.write("<br/>");
    }
    else if (op=="average")
    
       
    {
        var result=(parseInt(value1)+parseInt(value2))/2;
        document.write("average   is ="+result );
        document.write("<br/>");
    }
    else
    {
       displa("Invalid input :" );
        document.write("<br/>"); 
    }
    var choice=prompt("Do you want to continue (Y/N)::"," ");
    }
    while(choice=="Y"||choice=="y");
    </script>
1 Answers

There is a syntax error in your code ParseInt should be parseInt, additionnaly, it is recommended to use the static method of the Number object: Number.parseInt as it is generally safer.

Related