Jump to content

tapasa

Members
  • Posts

    5
  • Joined

  • Last visited

Posts posted by tapasa

  1. while (sexo !== "h" && sexo !== "H" && sexo !== "M" && sexo !== "m"){  // not done yet}while (sexo !== "h" || sexo !== "H" || sexo !== "M" || sexo !== "m"){  // not done yet}

    i think in theory the second code must work, was the first thingh i thought, but not, and i cant understand why the first yes and the other not :/

  2. To answer your first question, the reason is to make sure they've given a proper answer and not letting them continue until they do. The only answers allowed are "h", "H", "m" and "M", if other answers are given they're asked the question again.

     

    The answer to your second question is logic.

     

    You only want to ask the question again if all four of the conditions are met. The conditions being that the answer is not "h", not "H", not "m" and not "M". If you used an || operator then the condition is always met, since at least one of the four conditions is always true. If it's "H" then not "M" is true, if it's "M" then not "H" is true.

    Yeah, I understand the first part, but why the && and not ||. Sorry I'm spanish and I dont understand things like this in english haha. I understood the first part, but the condition is var sexo must be one of these, i first thought in || but my teacher told me that the || is not correct and the while never ends, but in && it works, but i think the condition catch all and must be sexo = hHmM, all at same time in &&, and in || the sexo var with one of the condition breaks, but not...this is that i cant understand

  3. var sexo; sexo=prompt("Introduce el sexo del alumno");while (sexo !== "h" && sexo !== "H" && sexo !== "M" && sexo !== "m"){	alert("sexo erróneo: " + sexo + ". Teclea de nuevo");	sexo=prompt("Introduce el sexo del alumno (Hombre(H o h), Mujer(M o m))");}alert("El sexo es: " + sexo + " es correcto");

     

    //This code above is right, but i cannot understand why, the sexo var must be "h" or "H" or "m" or "M" to break the while. Why if i put || instead of && it doesnt work and stay in the while?

     

    - Many thanks for you attention ^^

×
×
  • Create New...