Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

154
Visualizações
¿Script JS para probar una propiedad de cuadrilátero y generar la forma determinada?

Acabo de comenzar mi viaje de codificación y esperaba obtener ayuda. Me han pedido que cree un script que reciba la longitud de cada lado y los ángulos de cada esquina de un usuario (estos pueden estar 'codificados') y determine si la forma es un cuadrado, un rectángulo, un rombo o un parrelellogramo.

Estoy atascado con la lógica al hacer uso de declaraciones condicionales y no puedo pasar la prueba de un rombo. No sé si puedo usar una declaración de cambio; no estoy seguro de entender su uso.

por favor ayuda :D

 //Create a program that receives the length of each side and the angles of each corner (these can be hard-coded) and //determines whether the shape is a square, a rectangle, a rhombus or a parallelogram. console.log('Good day! Time to see what shape you are dealing with today.') sideLength_one = prompt("What is the length of the first side? "); sideLength_two = prompt("What is the length of the second side?"); sideLength_three = prompt("What is the length of the third side?"); sideLength_four = prompt("What is the length of the fourth side?"); console.log("Awesome! Now let's move to the angles."); angle_one = prompt("What is the measurement of angle one?"); angle_two = prompt("What is the measurement of angle two?"); angle_three = prompt("what is the measurement of angle three?"); angle_four = prompt("What is the measurement of angle four?"); //test the quadrilateral if (sideLength_one && sideLength_two && sideLength_three == sideLength_four){ console.log("Your shape is square!"); } else if (sideLength_one ==sideLength_three || sideLength_two == sideLength_four){ console.log("Your shape is a rectangle!"); } else if ((angle_one < 90 || angle_two < 90) && (sideLength_one && sideLength_two == sideLength_three)){ console.log ("Your shape is a rhombus!"); }

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

No se recomienda usar switch con sentencias. Considero que abusar de un efecto secundario
switch (true) { case statement1 .... }

En su lugar, debe agregar más &&s

 if (sideLength_one == sideLength_four && sideLength_two == sideLength_four && sideLength_three == sideLength_four)

en vez de

 if (sideLength_one && sideLength_two && sideLength_three == sideLength_four) 

 //Create a program that receives the length of each side and the angles of each corner (these can be hard-coded) and //determines whether the shape is a square, a rectangle, a rhombus or a parallelogram. console.log('Good day! Time to see what shape you are dealing with today.') sideLength_one = prompt("What is the length of the first side? "); sideLength_two = prompt("What is the length of the second side?"); sideLength_three = prompt("What is the length of the third side?"); sideLength_four = prompt("What is the length of the fourth side?"); console.log("Awesome! Now let's move to the angles."); angle_one = prompt("What is the measurement of angle one?"); angle_two = prompt("What is the measurement of angle two?"); angle_three = prompt("what is the measurement of angle three?"); angle_four = prompt("What is the measurement of angle four?"); //test the quadrilateral if (sideLength_one == sideLength_four && sideLength_two == sideLength_four && sideLength_three == sideLength_four) { console.log("Your shape is square!"); } else if (sideLength_one == sideLength_three || sideLength_two == sideLength_four) { console.log("Your shape is a rectangle!"); } else if ((angle_one < 90 || angle_two < 90) && (sideLength_one == sideLength_three && sideLength_two == sideLength_three)) { console.log("Your shape is a rhombus!"); } else console.log("Your shape is weird!");

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda