Faulty calculator exercise using javascript

technical talkiess
0

 Exercise javascript variable:- 

function calculation(isTimeToCalculateWrong = false){

    var num1 = parseInt(prompt("Enter the first number",1));

    var num2 = parseInt(prompt("Enter the second number",1));

    var operation = parseInt(prompt("Please add the operation do you want to perform \n 1. + (Enter 1 for addition) \n 2. - (Enter 2 for substraction) \n 3. * (Enter 3 for multiplecation) \n 4. / (Enter 4 for the division) "));


    if(isTimeToCalculateWrong){

        switch(operation){

            case 1:

                var total = num1 - num2;

                alert("The sum of the two number is" + total);

            break;

            case 2:

                var total = num1 / num2;

                alert("The sum of the two number is" + total);

            break;

            case 3:

                var total = num1 + num2;

                alert("The sum of the two number is" + total);

            break;

            case 4:

                var total = num1 ** num2;

                alert("The sum of the two number is" + total);

            break;

        }

    }else{

        switch(operation){

            case 1:

                var total = num1 + num2;

                alert("The sum of the two number is" + total);

            break;

            case 2:

                var total =num1 - num2;

                alert("The sum of the two number is" + total);

            break;

            case 3:

                var totalnum1 * num2;

                alert("The sum of the two number is" +total);

            break;

            case 4:

                var total = num1 / num2;

                alert("The sum of the two number is" + total);

            break;

        }

    }

    var ask_multiple_entry = confirm("Do you want to perform the multiple activity")

    var is_total_wrong = Math.random()

    is_total_wrong = is_total_wrong > 0.1 ? true : false;

    if(ask_multiple_entry){

        calculation(is_total_wrong)

    }

}

calculation()
Tags

Post a Comment

0Comments

Thanks you for commenting your questions. I will see question and respond you.

Post a Comment (0)