• python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Facebook Twitter Instagram
Devs Fixed
  • python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Devs Fixed
Home » Resolved: Javascript conditional not alerting when its condition is reached

Resolved: Javascript conditional not alerting when its condition is reached

0
By Isaac Tonny on 16/06/2022 Issue
Share
Facebook Twitter LinkedIn

Question:

I made a for loop in game() function to have the user input rock, paper, or scissors. If the game is played 5 times the loop is supposed to alert “You played 5 games already” but it doesn’t alert when the condition is met. I tried adding return before alert, I also tried using >= instead of === but it doesn’t work.

function game(){
for(let i = 0; i < 5; i++){ if(i < 5){ let getSelect = prompt("Choose Rock, Paper, or Scissors", ""); let getWinOrLose = alert(playRound(getSelect, computerPlay())); if( i === 5 ){ alert("You played 5 games already"); } } } } console.log(game()); [/code]

Check the code above ^
And here is the fiddle: https://jsfiddle.net/JaredDev/cbmLetuz/2/

Answer:

It won´t show the alert because condition i===5 is never reached since it is guarded by i<5. Plus the loop never reaches value of 5.

If you have better answer, please add a comment about this, thank you!

conditional-statements javascript
Share. Facebook Twitter LinkedIn

Related Posts

Resolved: How to get Union type from an array of objects in Flow?

24/03/2023

Resolved: Modify entity using Action in C#

24/03/2023

Resolved: How to give rank on datetime column group by another column with userid in it

24/03/2023

Leave A Reply

© 2023 DEVSFIX.COM

Type above and press Enter to search. Press Esc to cancel.