- 1
Javascript function and if statement doubts. , I dont know how to explain this , please look at my code in description
Pls look at my code . I know if I put the function in else statement it will work ., But is there any another way to work that. ?? https://code.sololearn.com/WOAS7Gca8KXM/?ref=app
12 ответов
+ 1
What do you mean?
a = true
if (a == true){
//the function should not work
}else{
// the function wants to work .
}
So what are you trying to do here? "else" will never execute, cuz you declared 'a' as true.
+ 1
Michal Doruch okay ,.It's just a mistake. .
a = 1
if (a==1 ){
} else {
// In the else statement i want to work the code ..
// I mean if the condition is true the code should not work
// When if false then wants to work .
}
Get it .?
+ 1
just test if a is different of 1:
if (a!=1) {
// the code run
}
else {
// the code not run
}
obviously, the else part is optional ^^
+ 1
you could also test for not any condition:
c = a==1;
if (!c) { /* executed */ }
or without assignement:
if (!(a==1)) { /* executed */ }
+ 1
visph no ,not like brother ,.
I will give you another example of same as my exact issue.
I think if you check the code , you will get what I mean.
There is two doubts to me .
Please consider that. ..
https://code.sololearn.com/WOAS7Gca8KXM/?ref=app
+ 1
just move the putgreen() call inside the else statement...
(also, you don't need the a=1 and check for it ^^)
0
visph what. ?? ..
???
I don't get that.
Also what about the first doubts. .?
The validation things. ?
0
You mean that your if statement is not working!?
Simply add return false at the end of your if statement:
if(name.value == '' || age.value == "") {
alert('Please fill in the form');
return false;
}
0
Radin Masiha yeah ,
I tried that ..
But no use ..
Just try that in my code. .
0
Yeah it worked i tried it
0
Make sure you write return false at the end of if statement. It works