1337coder
12-15-2006, 01:26 AM
Okay, something is not working. When I type:
var x = Math.PI();
it counts as an error, and causes the rest of the script to malfunction. So, instead of using the built-in javascript pi, I made my own. It usually works, but it does not work for the following code:
function spha(){
var di = prompt("Type the radius of the sphere", "")
if(di == 0){
}else{
var dj = di * di
var dk = dj * di
var dl = dk * pi
var dm = dl / 3
var dn = dm * 4
alert(di)
}
}
The prompt comes up, but nothing happens after that. It is not counted as an error, so I cannot do anything with a debugger. I learned, by taking away certain lines and observing, that the line "var dl = dk * pi" is the line causing the problem. When I use a number instead of a variable, it works. I can't do that, because at the begginging, I prompt the user if they want "3.14", or pi to 50 digits. The coding for that is:
function pivalue(){
var pivalue = prompt("Type 1 if you want pi to be 3.14, and type 2 if you want it to be pi recited to 50 digits. If you type something other than 1 or 2, pi will automatically represent 3.14", "")
if(pivalue == 1){
var pi = 3.14
else if(pivalue == 2){
var pi = 3.14159 26535 89793 23846 26433 83279 50288 41971 69399 37510
}else{
var pi == 3.14
}
}
The function "pivalue()" is triggered by body onLoad. I have tried it like that, and without a function. Neither worked. I have also tried simply stating "var pi = 3.14", but it still does not work. To recap, pi does not work if I contain it within a variable, it works when I type the numerical value instead of the variable, I need it to be in a variable, and it works fine in a variable elsewhere. Can anyone help me? Thanks in advance.
var x = Math.PI();
it counts as an error, and causes the rest of the script to malfunction. So, instead of using the built-in javascript pi, I made my own. It usually works, but it does not work for the following code:
function spha(){
var di = prompt("Type the radius of the sphere", "")
if(di == 0){
}else{
var dj = di * di
var dk = dj * di
var dl = dk * pi
var dm = dl / 3
var dn = dm * 4
alert(di)
}
}
The prompt comes up, but nothing happens after that. It is not counted as an error, so I cannot do anything with a debugger. I learned, by taking away certain lines and observing, that the line "var dl = dk * pi" is the line causing the problem. When I use a number instead of a variable, it works. I can't do that, because at the begginging, I prompt the user if they want "3.14", or pi to 50 digits. The coding for that is:
function pivalue(){
var pivalue = prompt("Type 1 if you want pi to be 3.14, and type 2 if you want it to be pi recited to 50 digits. If you type something other than 1 or 2, pi will automatically represent 3.14", "")
if(pivalue == 1){
var pi = 3.14
else if(pivalue == 2){
var pi = 3.14159 26535 89793 23846 26433 83279 50288 41971 69399 37510
}else{
var pi == 3.14
}
}
The function "pivalue()" is triggered by body onLoad. I have tried it like that, and without a function. Neither worked. I have also tried simply stating "var pi = 3.14", but it still does not work. To recap, pi does not work if I contain it within a variable, it works when I type the numerical value instead of the variable, I need it to be in a variable, and it works fine in a variable elsewhere. Can anyone help me? Thanks in advance.