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
  • Put your name on the first line in camelCase. Write a JavaScript function to generate a...

    Put your name on the first line in camelCase. Write a JavaScript function to generate a random number from 1 to 100. Determine if it is a small, medium or large number. Display random integer and its size. 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....

  • Write a Java application with a class name of Payroll, for the “Travel Agency”, that willCalculate...

    Write a Java application with a class name of Payroll, for the “Travel Agency”, that willCalculate the weekly paycheck for both Salaried and Hourly employees. Salaried employees will be paid 1/52 of their annual pay minus 18% withheld for federal and state taxes, as well as 4% for retirement pension. Salaried employees do not collect overtime pay. There are two types of Hourly employees; permanent employees and temporary weekly employees. •Permanent weekly employees will be paid their hourly rate minus...

  • Lab 1 Q1. Write a Python program with the following function building block. •All input values...

    Lab 1 Q1. Write a Python program with the following function building block. •All input values are to be taken fro m the user. •Ensure to check for possible error cases like mismatch of data type and input out of range, for every function.       Function 1: countVowels(sentence) – Function that returns the count of vowels in a sentence. Function 2: Sum of all even numbers between two numbers, identify number of parameters   Q2. Write a Python program that reads a...

  • For part one of this assignment, write a program (parse.c) that contains a function to parse...

    For part one of this assignment, write a program (parse.c) that contains a function to parse a single line of input and and prints out the individual tokens. Part 1 - Single Line Parser For part one of this assignment, you will need to learn how to do some parsing (or more accurately--lexing a line, you do not have to check for correctness). You have previously done some parsing with the cycle count tool perhaps using functions such as strcmp....

  • In this assignment you are asked to write a Python program to determine all the prime...

    In this assignment you are asked to write a Python program to determine all the prime numbers in between a range and store them in a list that will be printed when the range is searched. The user is prompted for two positive integer values as input, one is the start of the range and the other is the end of the range. If the user gives a negative value or enters a second number that is lower than the...

  • In C++ Please please help.. Assignment 5 - Payroll Version 1.0 In this assignment you must create and use a struct to hold the general employee information for one employee. Ideally, you should use an...

    In C++ Please please help.. Assignment 5 - Payroll Version 1.0 In this assignment you must create and use a struct to hold the general employee information for one employee. Ideally, you should use an array of structs to hold the employee information for all employees. If you choose to declare a separate struct for each employee, I will not deduct any points. However, I strongly recommend that you use an array of structs. Be sure to read through Chapter...

  • Add JavaScript code in the “find_primeV2.js” to allow users to enter a number, and then based...

    Add JavaScript code in the “find_primeV2.js” to allow users to enter a number, and then based on the number of user enters, to find out how many prime numbers there are up to and including the user inputted number and then display them on the web page. The following are the detailed steps to complete this assignment: Step 1. [30 points] In “find_primeV2.js”, complete isPrime() function by (1) Adding one parameter in function header. That parameter is used to accept...

  • (JAVA Please) Program 1: FICA!? What’s FICA? If you’re taking this course, chances are that you’re...

    (JAVA Please) Program 1: FICA!? What’s FICA? If you’re taking this course, chances are that you’re going to make a pretty good salary – especially 3 to 5 years after you graduate. When you look at your paycheck, one of the taxes you pay is called FICA – or Federal Insurance Contributions Act. In simplest terms, it’s what funds our Social Security and Medicare systems (and the more that you work, the more you get). Interestingly, your employer will pay...

  • I am having a hard time with my program to assignment 4.12. Here are the instructions:...

    I am having a hard time with my program to assignment 4.12. Here are the instructions: The Payroll Department keeps a list of employee information for each pay period in a text file. The format of each line of the file is the following: <last name> <hours worked> <hourly wage> Write a program that inputs a filename from the user and prints to the terminal a report of the wages paid to the employees for the given period. The report...

  • Program 1: Social Security Payout. If you’re taking this course, chances are that you’re going to...

    Program 1: Social Security Payout. If you’re taking this course, chances are that you’re going to make a pretty good salary – especially 3 to 5 years after you graduate. When you look at your paycheck, one of the taxes you pay is called Social Security. In simplest terms, it’s a way to pay into a system and receive money back when you retire (and the longer you work and the higher your salary, the higher your monthly benefit). Interestingly,...

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