How to cancel a var ??

+1 Rafae Raees · December 10, 2015
Hello, I was just messing around with JavaScript and doing random shit until I found this "problem".

I am creating a simple Calculator and want to square root an integer without the code asking me for the second number. 


It is hard to explain just copy my code and see for your self.

Thanks. 

Post a Reply

Replies

Oldest  Newest  Rating
0 Rafae Raees · December 10, 2015
Here is my code...

<!doctype html>

<html>
<title>GroupCode</title>
<head> 

</head>
<body>
<style type = "text/css">

</style>
</body>
<from>

</from>
<script>
var num1 = prompt("Enter your first number");
var operator = prompt("Choose your operator");
var num2 = prompt("Choose your second number");

if(operator == '+'){
document.write(num1+num2);

}
if(operator == '-'){
document.write(num1-num2);

}
if(operator == '*'){
document.write(num1*num2);

}
if(operator == '/'){
document.write(num1/num2);

}
if(operator == '^2'){
document.write(Math.sqrt(num1));

}
if(operator == '^2'){
num2 == null;
}

</script>
</html>
0 Rafae Raees · December 10, 2015
Ignore the last if statement 
  • 1

Javascript

107,057 followers
About

A scripting language that is added to standard HTML to create interactive effects, apps, games for the browser.

Links
Moderators