2

It's a simple calculator, only with javascript. Adding does it without problem, but when I want to subtract, add.

``````var eleccion = prompt("Qué operación querés realizar? Las opciones son: Suma, Resta, Multiplicacion y Division")
var primer = prompt("Primer número?")
var segundo = prompt("Segundo número?")

if (eleccion == "Suma" || "suma") {
document.write("El resultado es " + (Number(primer) + Number(segundo)))
} else if (eleccion == "Resta" || "resta") {
document.write("El resultado es " + (Number(primer) - Number(segundo)))
}``````

source

2

You have a problem with your conditions. The correct way is like this:

``````var eleccion = prompt("Qué operación querés realizar? Las opciones son: Suma, Resta, Multiplicacion y Division")
var primer = prompt("Primer número?")
var segundo = prompt("Segundo número?")

if (eleccion == "Suma" || eleccion == "suma"){
document.write("El resultado es " + (Number(primer) + Number(segundo)))}
else if (eleccion == "Resta" || eleccion == "resta"){
document.write("El resultado es " + (Number(primer) - Number(segundo)))}``````

0

The first evaluation gives as true (true) always

``````if (eleccion == "Suma" || "suma"){
``````

if `eleccion` equals `"resta"` the first part:

``````if (eleccion == "Suma"
``````

will give false (false)

however the second part

`````` "suma"){
``````

will give true (true), this together would be:

``````if (false || true){
``````

If false or true, true