osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

JavaScript Calculator Program


Hi People, I am working on a simple calculator which uses operands (+-*/).
The program allows me to choose an operand and enter the first two values, but when it gets to doing the maths, it gives me an error on 
"console.log ("The result is ", res);" under the + operand.
(error code reads: Println is not a function)

Any help will be much appreciated. 
Thanks in advance.

-----------------------------------------------------------

console.log ("1. Add numbers");	 	       	  	  	  	    	   	
console.log("2. Subtract numbers");	 	       	  	  	  	    	   	
console.log("3. Multiply numbers");	 	       	  	  	  	    	   	
console.log("4. Divide numbers");	 	       	  	  	  	    	   	
	 	       	  	  	  	    	   	
console.log = prompt("What's your choice?");	 	       	  	  	  	    	   	
	 	       	  	  	  	    	   	
var num1 = prompt("Enter the first number ");	 	       	  	  	  	    	   	
firstnumber = prompt;	 	       	  	  	  	    	   	
	 	       	  	  	  	    	   	
var num2 = prompt("Enter the second number ");	 	       	  	  	  	    	   	
secondnumber = prompt;	 	       	  	  	  	    	   	
	 	       	  	  	  	    	   	
var choice;	 	       	  	  	  	    	   	
var res;	 	       	  	  	  	    	   	
	 	       	  	  	  	    	   	
if (choice == 1);	 	       	  	  	  	    	   	
    result = (num1 + num2);	 	       	  	  	  	    	   	
    console.log ("The result is ", res);	 	       	  	  	  	    	   	
	 	       	  	  	  	    	   	
if (choice == 2);	 	       	  	  	  	    	   	
    result = (num1 - num2);	 	       	  	  	  	    	   	
    console.log ("The result is = ", res);	 	       	  	  	  	    	   	
	 	       	  	  	  	    	   	
if (choice == 3);	 	       	  	  	  	    	   	
    result = (num1 * num2);	 	       	  	  	  	    	   	
    console.log ("The result is = ", res);	 	       	  	  	  	    	   	
	 	       	  	  	  	    	   	
if (choice == 4);	 	       	  	  	  	    	   	
    result = (num1 / num2);	 	       	  	  	  	    	   	
    console.log ("The result is = ", res);

-------------------------------------------------------------------