Skip to content

Commit

Permalink
Arreglado bug de división de 0
Browse files Browse the repository at this point in the history
  • Loading branch information
CANCI0 committed Apr 4, 2024
1 parent 407c1a7 commit 40e4e1a
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions webapp/src/pages/Calculadora/Calculadora.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,13 @@ const CalculadoraHumana = () => {
let num1 = Math.floor(Math.random() * 10 + 1);
let operation = `${valSubmit} ${operator} ${num1}`;
if (operator === "/") {
if(valSubmit === 0){
return `${valSubmit} ${operator} ${1}`;
}
let numCandidates = findDivisors(valSubmit);
let num2 =
numCandidates[Math.floor(Math.random() * numCandidates.length)];
operation = `${valSubmit} ${operator} ${num2}`;
return `${valSubmit} ${operator} ${num2}`;
}
return operation;
};
Expand Down Expand Up @@ -139,7 +142,7 @@ const CalculadoraHumana = () => {
onChange={(e) => setValSubmit(e.target.value)}
onKeyDown={handleKeyDown}
/>
<Button onClick={() => handleAnswer(Number(valSubmit))}>
<Button mt={3} onClick={() => handleAnswer(Number(valSubmit))}>
{" "}
Enviar{" "}
</Button>
Expand Down

0 comments on commit 40e4e1a

Please sign in to comment.