- 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

20th May 2021, 9:47 AM
ShamsuCm
12 Antworten
+ 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.
20th May 2021, 12:12 PM
Michal Doruch
+ 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 .?
20th May 2021, 1:26 PM
ShamsuCm
+ 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 ^^
20th May 2021, 1:28 PM
visph
visph - avatar
+ 1
you could also test for not any condition: c = a==1; if (!c) { /* executed */ } or without assignement: if (!(a==1)) { /* executed */ }
20th May 2021, 1:31 PM
visph
visph - avatar
+ 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
20th May 2021, 2:29 PM
ShamsuCm
+ 1
just move the putgreen() call inside the else statement... (also, you don't need the a=1 and check for it ^^)
20th May 2021, 2:44 PM
visph
visph - avatar
0
visph what. ?? .. ??? I don't get that. Also what about the first doubts. .? The validation things. ?
20th May 2021, 2:49 PM
ShamsuCm
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; }
21st May 2021, 6:10 AM
🇮🇱 Radin Masiha 🇮🇱
🇮🇱 Radin Masiha 🇮🇱 - avatar
0
Radin Masiha yeah , I tried that .. But no use .. Just try that in my code. .
21st May 2021, 11:20 AM
ShamsuCm
0
Yeah it worked i tried it
21st May 2021, 11:42 AM
🇮🇱 Radin Masiha 🇮🇱
🇮🇱 Radin Masiha 🇮🇱 - avatar
0
Make sure you write return false at the end of if statement. It works
21st May 2021, 11:43 AM
🇮🇱 Radin Masiha 🇮🇱
🇮🇱 Radin Masiha 🇮🇱 - avatar