In: Computer Science
Task #1 It is orientation day at the college. Students need to go to a specific room based on their status. Their status can be either international full-time, domestic full-time, or domestic parttime. Your task is to complete a program that will do the following: • Ask a student for their name • Ask them for their status – keep the status simple in order to ensure that you do not have to handle a wide variety of inputs. For example, you can ask them to enter I for international full-time, F for domestic full-time, and P for domestic part-time. • Display a message that lists their name and the room that they must go to. If the students are international full-time they are to be directed to room 227. If they are domestic full-time they must meet in room 123. If they are domestic part-time they must meet in room 055. Create the JavaScript program for task #1
Hello,
I have created javascript code based on your requirement. I have used alert to display student information finally. Please let me know if any changes required.
JavaScript code snippet:
// Prompt for Stundent name and assign user input to name variable
var name = prompt('Please enter your name');
// Prompt for Stundent status and assign user input to status variable
var status = prompt('Please enter your status. \n Enter I for international full-time \n Enter F for domestic full-time \n Enter P for domestic part-time');
// Declare roomNo variable
var roomNo;
// Assign roomNo based on student status by using if-else statements
if(status==='I') {
roomNo = '227';
} else if(status==='F') {
roomNo = '123';
} else if(status==='P') {
roomNo = '055';
}
// Displaying message that lists out stundent name and room they need to go by using alert
alert("Student Name : " + name + "\nRoom Number to go : " + roomNo);
Output:
If you want to see the output message in console you can use below code snippet
// Prompt for Stundent name and assign user input to name variable
var name = prompt('Please enter your name');
// Prompt for Stundent status and assign user input to status variable
var status = prompt('Please enter your status. \n Enter I for international full-time \n Enter F for domestic full-time \n Enter P for domestic part-time');
// Declare roomNo variable
var roomNo;
// Assign roomNo based on student status by using if-else statements
if(status==='I') {
roomNo = '227';
} else if(status==='F') {
roomNo = '123';
} else if(status==='P') {
roomNo = '055';
}
// Displaying message that lists out stundent name and room they need to go by using console log
console.log("Student Name : " + name + "\nRoom Number to go : " + roomNo);
Output would be in console as like below