Question: use strict; / * New Perspectives on HTML 5 , CSS 3 , and JavaScript 6 th Edition Tutorial 1 4 Case Problem 2 Filename:
"use strict";
New Perspectives on HTML CSS and JavaScript th Edition
Tutorial
Case Problem Filename: ccstaff.js
Constructor function for the employee class
function employeeid firstName, lastName, dept, position, email, phone, photo
this.id id;
this.firstName firstName;
this.lastName lastName;
this.dept dept;
this.position position;
this.email email;
this.phone phone;
this.photo photo;
;
Object literal for search results
var searchResult
employees :
sortById : function
this.employees.sortfunctionab
if aid bidreturn ;
else return ;
;
;
Event listener to retrieve and display employee records matching the search condition
var getTable document.getElementByIdtableBody;
document.getElementByIdsearchButtonaddEventListenerclick function
var tableBody document.querySelectorstaffTable tbody";
var tableCaption document.querySelectorstaffTable caption";
;
tableBody.removeChildren;
searchResult.employees ;
staff.directory.forEachfunctionrecord
var nameSearch document.getElementByIdnameSearchvalue;
var nameSearchType document.getElementByIdnameSearchTypeselectedValue;
;
switchnameSearchType
case "contains":
var nameRegExp new RegExpnameSearchi; break;
case "beginsWith":
var nameRegExp new RegExp nameSearch, i; break;
case "exact":
var nameRegExp new RegExp nameSearch $i; break;
;
var foundName nameRegExp.testrecordlastName;
var positionSearch document.getElementByIdpositionSearchvalue;
var positionSearchType document.getElementByIdpositionSearchTypeselectedValue;
switch positionSearchType
case "contains":
var positionRegExp new RegExppositionSearchi; break;
case "beginsWith":
var positionRegExp new RegExp positionSearch, i; break;
case "exact":
var positionRegExp new RegExp positionSearch $i; break;
;
testing for a position
var foundPosition positionRegExp.testrecordposition;
var deptSearch document.getElementByIddeptSearchselectedValue;
ifdeptSearch deptSearch record.dept
var foundDept true;
;
if foundName && foundPosition && foundDept
searchResult.employees.pushnew employee
record.id
record.firstName,
record.lastName,
record.dept,
record.position,
record.email,
record.phone,
record.photo
;
;
change caption to # of records found
tableCaption.textContent searchResult.employees.length;
searchResult.sortById;
fill table with matching employees
searchResult.employees.forEachfunctionrecord
tableBody.innerHTML
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
