Question

Write a JavaScript function to determine the building assignment for employees. Input the department and pay...

Write a JavaScript function to determine the building assignment for employees. Input the department and pay type. Salaried IT employees go to Iona. Hourly IT employees to to Ithaca. Salaried manufacturing employees to to Miner while hourly manufacturing employees go to McCook. Salaried accounting employees go to Armstrong while hourly manufacturing employees go to Aldrin. Display their building assignment

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Here is the answer for your requirement in JavaScript Programming language.

NOTE:

1.To give you better understanding of how the function works, I have created an HTML file through which you can give input.

2.While you are giving input, a table will be displayed with Department name,paytype and building assignment.

JavaScript Code :

<script>
function building()
{
       //To prompt the user for department and paytypes
   var department = prompt("Enter Department Name\nAvailable Departments are : \n1.IT\n2.Manufacturing\n3.Accounting");
   var paytype = prompt("Enter Pay type\nAvailable Paytypes are : \n1.Salaried\n2.Hourly");
  
   //Getting the table with id "building" from webpage
   var table = document.getElementById("building");  
          
   //If-else statements with particular department with given paytypes will be checked
   //As per the requrement employee with given department with given paytype
   //will be assigned to particular person assigned.
   if(department == "IT" && paytype == "Salaried")
   {     
       //To create a row in the table
       var row = table.insertRow(-1);
       //To insert cells<td>s in each row
       var cell1 = row.insertCell(0);
       var cell2 = row.insertCell(1);
       var cell3 = row.insertCell(2);
       //To insert data in each cell
       cell1.innerHTML = department;
       cell2.innerHTML = paytype;
      cell3.innerHTML = "Lona";
   }
   else if(department == "IT" && paytype == "Hourly")
   {  
       var row = table.insertRow(-1);
       var cell1 = row.insertCell(0);
       var cell2 = row.insertCell(1);
       var cell3 = row.insertCell(2);
       cell1.innerHTML = department;
       cell2.innerHTML = paytype;
      cell3.innerHTML = "Ithica";
   }
   else if(department == "Manufacturing" && paytype == "Salaried")
   {  
       var row = table.insertRow(-1);
       var cell1 = row.insertCell(0);
       var cell2 = row.insertCell(1);
       var cell3 = row.insertCell(2);
       cell1.innerHTML = department;
       cell2.innerHTML = paytype;
      cell3.innerHTML = "Miner";
   }
   else if(department == "Manufacturing" && paytype == "Hourly")
   {  
       var row = table.insertRow(-1);
       var cell1 = row.insertCell(0);
       var cell2 = row.insertCell(1);
       var cell3 = row.insertCell(2);
       cell1.innerHTML = department;
       cell2.innerHTML = paytype;
      cell3.innerHTML = "McCook";
   }
   else if(department == "Accounting" && paytype == "Salaried")
   {  
       var row = table.insertRow(-1);
       var cell1 = row.insertCell(0);
       var cell2 = row.insertCell(1);
       var cell3 = row.insertCell(2);
       cell1.innerHTML = department;
       cell2.innerHTML = paytype;
      cell3.innerHTML = "Armstrong";
   }
   else if(department == "Accounting" && paytype == "Hourly")
   {     
       var row = table.insertRow(-1);
       var cell1 = row.insertCell(0);
       var cell2 = row.insertCell(1);
       var cell3 = row.insertCell(2);
       cell1.innerHTML = department;
       cell2.innerHTML = paytype;
      cell3.innerHTML = "Aldrin";
   }//If input is invalid then an alert message is displayed
   else
   {
       window.alert("Invalid details given..Please check");
   }
}
</script>

HTML file with internal JavaScript code in it.

Building_Assignment.html

<!DOCTYPE html>
<html>
<head>
<title>Building Assignment</title>
<style>
   table,th,td
   {
       cell-spacing: 15px;
       border : 1px solid green;
       border-collapse : collapse;
   }
   th
   {
       background-color:lightgreen;
   }
</style>
<script>
function building()
{
       //To prompt the user for department and paytypes
   var department = prompt("Enter Department Name\nAvailable Departments are : \n1.IT\n2.Manufacturing\n3.Accounting");
   var paytype = prompt("Enter Pay type\nAvailable Paytypes are : \n1.Salaried\n2.Hourly");
  
   //Getting the table with id "building" from webpage
   var table = document.getElementById("building");  
          
   //If-else statements with particular department with given paytypes will be checked
   //As per the requrement employee with given department with given paytype
   //will be assigned to particular person assigned.
   if(department == "IT" && paytype == "Salaried")
   {     
       //To create a row in the table
       var row = table.insertRow(-1);
       //To insert cells<td>s in each row
       var cell1 = row.insertCell(0);
       var cell2 = row.insertCell(1);
       var cell3 = row.insertCell(2);
       //To insert data in each cell
       cell1.innerHTML = department;
       cell2.innerHTML = paytype;
      cell3.innerHTML = "Lona";
   }
   else if(department == "IT" && paytype == "Hourly")
   {  
       var row = table.insertRow(-1);
       var cell1 = row.insertCell(0);
       var cell2 = row.insertCell(1);
       var cell3 = row.insertCell(2);
       cell1.innerHTML = department;
       cell2.innerHTML = paytype;
      cell3.innerHTML = "Ithica";
   }
   else if(department == "Manufacturing" && paytype == "Salaried")
   {  
       var row = table.insertRow(-1);
       var cell1 = row.insertCell(0);
       var cell2 = row.insertCell(1);
       var cell3 = row.insertCell(2);
       cell1.innerHTML = department;
       cell2.innerHTML = paytype;
      cell3.innerHTML = "Miner";
   }
   else if(department == "Manufacturing" && paytype == "Hourly")
   {  
       var row = table.insertRow(-1);
       var cell1 = row.insertCell(0);
       var cell2 = row.insertCell(1);
       var cell3 = row.insertCell(2);
       cell1.innerHTML = department;
       cell2.innerHTML = paytype;
      cell3.innerHTML = "McCook";
   }
   else if(department == "Accounting" && paytype == "Salaried")
   {  
       var row = table.insertRow(-1);
       var cell1 = row.insertCell(0);
       var cell2 = row.insertCell(1);
       var cell3 = row.insertCell(2);
       cell1.innerHTML = department;
       cell2.innerHTML = paytype;
      cell3.innerHTML = "Armstrong";
   }
   else if(department == "Accounting" && paytype == "Hourly")
   {     
       var row = table.insertRow(-1);
       var cell1 = row.insertCell(0);
       var cell2 = row.insertCell(1);
       var cell3 = row.insertCell(2);
       cell1.innerHTML = department;
       cell2.innerHTML = paytype;
      cell3.innerHTML = "Aldrin";
   }//If input is invalid then an alert message is displayed
   else
   {
       window.alert("Invalid details given..Please check");
   }
}
</script>
</head>
<body>
   <!--Table with particular id "building"-->
   <center><table id="building" width="50%">
   <tr><th>Department</th><th>Pay Type</th><th>Building Assignment</th></tr>
   </table>  
   <!--Button that allows you to add an employee to table-->
   </center><br/><br/><br/>
   <center><button onclick="building()" style="background-color:green;width:100px;color:white;border-radius:5px;border-color:green;">
       Add an Employee</button></center>
</body>
</html>

SCREENSHOTS

OUTPUT

After entering some values the table looks like :

NOTE : As complete flow is not mentioned including the design of output took this type of webpage, my sincere apalogy if web page does not meet your idea. But the function is written completely as per the question given. Any doubts can be explained with pleasure :)

Add a comment
Know the answer?
Add Answer to:
Write a JavaScript function to determine the building assignment for employees. Input the department and pay...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT