JS if statement wont work [closed]
Clash Royale CLAN TAG#URR8PPP
JS if statement wont work [closed]
Just using a normal if-statement to check if something is equal or higher/lower than the actual result.
Only getting the else alert..
function generatePrice(b)
var i;
var a = ;
var c = 24;
var deg = Math.floor(360/c);
var prev_deg=0;
for(i=1; i < 25; i++)
var tmp_deg = i * deg;
a[i] = 'begin':prev_deg,'end':tmp_deg;
prev_deg = tmp_deg + 1;
if(a[22].begin >= b && a[22].end <= b)
alert("u WON");
if(a[6].begin >= b && a[6].end <= b)
alert("u WON");
if(a[13].begin >= b && a[13].end <= b)
alert("u WON");
else
alert("Better luck next time");
This question appears to be off-topic. The users who voted to close gave this specific reason:
begin
end
maybe the conditions are all false?
– Luca Kiebel
Aug 10 at 13:07
Please post all of the relevant code so that we can help you.
– hev1
Aug 10 at 13:07
We can't help you if you don't show us the data that your logic is working off of.
– Scott Marcus
Aug 10 at 13:09
Even after the edit, you don't tell us what number you pass in that becomes
b
, so how can we help you?– Jared Smith
Aug 10 at 13:16
b
1 Answer
1
Maybe you need a switched check
begin <= b <= end
where b
is inside of the interval. Then you need to exit the function
b
if (a[22].begin <= b && b <= a[22].end)
alert('Won!');
return;
if (a[6].begin <= b && b <= a[6].end)
alert('Won!');
return;
if (a[13].begin <= b && b <= a[13].end)
alert('Won!');
return;
alert('Sorry!');
or to chain the conditions with else
if (a[22].begin <= b && b <= a[22].end)
alert('Won!');
else if (a[6].begin <= b && b <= a[6].end)
alert('Won!');
else if (a[13].begin <= b && b <= a[13].end)
alert('Won!');
else
alert('Sorry!');
function generatePrice(b)
var i;
var a = ;
var c = 24;
var deg = Math.floor(360 / c);
var prev_deg = 0;
for (i = 1; i < 25; i++)
var tmp_deg = i * deg;
a[i] = 'begin': prev_deg, 'end': tmp_deg ;
prev_deg = tmp_deg + 1;
if (a[22].begin <= b && b <= a[22].end )
alert("u WON");
return;
if (a[6].begin <= b && b <= a[6].end )
alert("u WON");
return;
if (a[13].begin<= b && b <=a[13].end)
alert("u WON");
return;
alert("Better luck next time");
generatePrice(80);
Still won't work..
– J. van Veltom
Aug 10 at 13:15
I've tried both things but it still won't display the alert
– J. van Veltom
Aug 10 at 13:30
What is
begin
andend
?– CodeF0x
Aug 10 at 13:07