Question

In: Computer Science

3.32 Prog4-Branches-Listing names A university has a web page that displays the instructors for a course,...

3.32 Prog4-Branches-Listing names A university has a web page that displays the instructors for a course, using the following algorithm: If only one instructor exists, the instructor's first initial and last name are listed. If two instructors exist, only their last names are listed, separated by /. If three exist, only the first two are listed, with "/ …" following the second. If none exist, print "TBD". Given six words representing three first and last names (each name a single word; latter names may be "none none"), output one line of text listing the instructors' names using the algorithm. If the input is "Ann Jones none none none none", the output is "A. Jones". If the input is "Ann Jones Mike Smith Lee Nguyen" then the output is "Jones / Smith / …". Hints: Use an if-else statement with four branches. The first detects the situation of no instructors. The second one instructor. Etc. Detect whether an instructor exists by checking if the first name is "none".

Solutions

Expert Solution

<!DOCTYPE html>
<html>
<body>

<h2>Instructors for Course IE9685</h2>
<p id="displayInstructors"></p>

<script>
var input = ""; //Output: TBD
var input = "Ann Jones none none none none"; //Output: A. Jones
var input = "Ann Jones"; //Output: A. Jones
var input = "Ann Jones Mike Smith none none"; //Output: Jones / Smith
var input = "Ann Jones Mike Smith"; //Output: Jones / Smith
var input = "Ann Jones Mike Smith Lee Nguyen"; //Output: Jones / Smith /...

// Checks whether an instructor exists by "none"
var Instructors = input.split(" ");
while(Instructors.indexOf("none") != -1){
        Instructors.splice(Instructors.indexOf("none"), 1);
    }

var text = "";

// If-else tatement to check the number of instructors
if (Instructors.length == 1){
        text = "TBD";
} else if (Instructors.length == 2) {
        text += Instructors[0][0] + ". " + Instructors[1];
} else if (Instructors.length == 4) {
        text += Instructors[1] + " / " + Instructors[3];
} else if (Instructors.length == 6){
        text += Instructors[1] + " / " + Instructors[3] + " /...";
}

// Used to display the instructors for a course in the webpage
var element = document.getElementById("displayInstructors");
element.innerHTML = text;
</script>

</body>
</html>

Related Solutions

IN JAVA 12.11 PRACTICE: Branches*: Listing names A university has a web page that displays the...
IN JAVA 12.11 PRACTICE: Branches*: Listing names A university has a web page that displays the instructors for a course, using the following algorithm: If only one instructor exists, the instructor's first initial and last name are listed. If two instructors exist, only their last names are listed, separated by /. If three exist, only the first two are listed, with "/ …" following the second. If none exist, print "TBD". Given six words representing three first and last names...
You are designing a web page that allows users to create an event listing. The event...
You are designing a web page that allows users to create an event listing. The event listing should include the date, time, location, title, phone, email, coordinator, and description of the event. The location should be between 10 and 100 characters long. The title should be between 1 and 50 characters long. The description should be between 10 and 200 characters long. Phone number consists of numbers and dashes. Email has to have an @ symbol. All data elements should...
You are designing a web page that allows users to create an event listing. The event...
You are designing a web page that allows users to create an event listing. The event listing should include the date, time, location, title, phone, email, coordinator, and description of the event. The location should be between 10 and 100 characters long. The title should be between 1 and 50 characters long. The description should be between 10 and 200 characters long. Phone number consists of numbers and dashes. Email has to have an @ symbol. All data elements should...
Create a web page using PHP and HTML that contains a list of movie names available...
Create a web page using PHP and HTML that contains a list of movie names available for rent (at least 10 movies), so that each time you visit the home page, you see a different order of movies in the list. The movie names are required. 2) The rental price for each movie ranges between $1.99 to $7.99. • Create an associative array with a code for the movie as the key (e.g., movie1, movie2, etc.) and the associated rental...
Problem 4.3.8. In order to guarantee smooth operation, the University has three web- servers. Each can...
Problem 4.3.8. In order to guarantee smooth operation, the University has three web- servers. Each can handle the traffic by itself, and the probability that each is not working on a given day is 10%, independently of the other servers. Assuming that the system is up, what is the probability that only one server is functioning?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT