+ 2
Help with if statement!
I want to do something like this: if(functionName()==true) { //do this } I didn't think something like this was gonna work but I don't know how to do this.
11 Respostas
+ 4
yeah it will worked, Now you just need to define the function, but make sure it should return a boolean value or in terma of numbers ( 0 = false, or any other number is for true )
function main() {
if(functionName() == true) // đ calling the function
console.log("worked")
}
// function defination đđđđ
function functionName() {
return true;
}
+ 3
it will work if function returns true
+ 2
Lego in Motion
Why you don't think?
If function will return true then definitely if condition will execute.
+ 2
Subhadeep Mandal
What about this:
bool isEven(int num) {
return num % 2 == 0;
}
+ 2
it will work if function returns boolean
0
The way I understand if statement,
When an if is declared
Like this if (here you write the condtion ie 5===5)
Now if the condition is true then {only will the code in here will be executed}
0
bool isEven(int num){
if (num%2==0)
return true;
else
return false;
}
//wherever you want to apply
if(isEven(6))
//do this
0
AÍąJ I never said I don't think that.đ thanks for the help but it's not really working. So I just need to put:
return true;
?
0
It lookes like js, if statement on js is like this if (function == 1) {what happens}
- 1
looks like you still have same confusion so i created this simple example i hope it will solve your problem
https://code.sololearn.com/Wh02DZdl19V3/?ref=app
- 1
https://www.sololearn.com/discuss/3026687/?ref=app
https://www.sololearn.com/discuss/3026746/?ref=app
https://www.sololearn.com/discuss/3026922/?ref=app
https://www.sololearn.com/discuss/3027016/?ref=app
https://www.sololearn.com/discuss/3026999/?ref=app
https://www.sololearn.com/discuss/3027029/?ref=app
https://www.sololearn.com/discuss/3026901/?ref=app