Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

150
Views
JS script to test a quadrilateral property and output the determined shape?

I have just started my coding journey and was hoping to get some help. I have been asked to create a script that receives the length of each side and the angles of each corner from a user (these can be 'hard coded') and determines whether the shape is a square, rectangle, rhombus or a parrelellogram.

I am stuck with the logic while making use of conditional statements and I cannot get past the proof of a rhombus. I do not know if I can use a switch statement - I am not confident that I understand its use.

Please help :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 answers
Answer question

0

It is not recommended to use switch with statements. I consider that to be abusing a side effect
switch (true) { case statement1 .... }

Instead you need to add more &&s

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

instead of

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!