How can I stop a function from further running after an if condition.Like if x>=5 ...function should stops and a message display | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How can I stop a function from further running after an if condition.Like if x>=5 ...function should stops and a message display

JavaScript

1st Apr 2018, 4:33 PM
Manpreet Singh
Manpreet Singh - avatar
4 Answers
+ 1
You mean as follows function mymessage(message, condition ) { if (condition){ return; } console.log(message); }
1st Apr 2018, 4:38 PM
josh mizzi
josh mizzi - avatar
0
Hi Manpreet I think you want a while loop while (counter < 5) { // do my game function stuff counter++; } console.log("Game Over");
1st Apr 2018, 6:12 PM
Mike Choy
Mike Choy - avatar
0
you mean while or do while
1st Apr 2018, 6:31 PM
Manpreet Singh
Manpreet Singh - avatar
- 1
No I want to set a counter for no. of turns if user play 5 turns then ok if counter reaches 5 then function should stop and just give a message you loose or win like this.
1st Apr 2018, 4:45 PM
Manpreet Singh
Manpreet Singh - avatar