84.6k views
2 votes
Select an existing page from your website or create a new page (this new page should be in your website) of your choice and modify it to include JavaScript. This page must include the following:

An external JavaScript document linked to the page, that a conditional statement that writes some type of variable text on an HTML page A switch statement that displays a message, such as "Welcome, Rasmussen Students!" A random statement that displays a message depending on the time of day.

User Ataulm
by
7.9k points

1 Answer

3 votes

Final answer:

To modify a web page to include JavaScript, follow these steps: linking an external JavaScript document, writing variable text conditional statements, redirect statements that display messages, and random statements that display time-based messages.

Step-by-step explanation:

To add JavaScript to an existing web page, you can follow these steps:

  • Linking an External JavaScript Document: To link an external JavaScript document to the page, you can create a new JavaScript file (e.g., script.js) and then link it to the HTML page using the
  • Conditional Statement Writing Variable Text: You can use a conditional statement in the linked JavaScript file to write variable text on the HTML page. For instance, the following code snippet demonstrates how to write variable text based on a condition:

var age = 25;

if (age >= 18) {

document.write("You are an adult.");

} else {

document.write("You are a minor.");

}

  • Switch Statement Displaying a Message: A switch statement can be used in the JavaScript file to display a message based on certain conditions. Here’s an example of how you can implement a switch statement:

var userType = "Rasmussen";

switch (userType) {

case "Rasmussen":

document.write("Welcome, Rasmussen Students!");

break;

default:

document.write("Welcome!");

break;

}

  • Random Statement Displaying Message Based on Time of Day: To display a message depending on the time of day, you can use JavaScript’s Date object along with conditional statements. The following code snippet illustrates how you can achieve this:

var time = new Date().getHours();

if (time < 12) {

document.write("Good morning!");

} else if (time < 18) {

document.write("Good afternoon!");

} else {

document.write("Good evening!");

}

By incorporating these elements into your existing web page, you can enhance its interactivity and provide dynamic content based on various conditions.

User Clocher Zhong
by
8.4k points