Question: How do I write the following code? Using If and Else If Declare and initialize a new variable to hold the current date. Declare another
How do I write the following code?
Using If and Else If
Declare and initialize a new variable to hold the current date.
Declare another variable to hold the day of the week.
Using the variable declared in Step 1, assign the value of the variable declared in Step 2 to the day of the week ( hint: getDay() ).
Declare a variable to hold a message that will be displayed.
Using an if statement, when the day of the week is a weekday (i.e. Monday - Friday), set the message variable to the string 'Hang in there!'
Using an else statement, set the message variable to 'Woohoo! It is the weekend!'
Switch, Case, Break
Declare a new variable to hold another message.
Use switch, case and break to set the message variable to the day of the week as a string (e.g. Sunday, Monday, etc.) using the day of week variable declared in Step 2 above.
Output Changes
Assign the value of the first message variable to the HTML element with an ID of message1.
Assign the value of the second message variable to the HTML element with an ID of message2.
Fetch
Declare a global empty array variable to store a list of temples
Declare a function named output that accepts a list of temples as an array argument and does the following for each temple:
Creates an HTML
Creates an HTML
element and add the temple's templeName property to it.
Creates an HTML
element and add the temple's location property to it.
Creates an HTML
element and add the temple's dedicated property to it.
Creates an HTML element and add the temple's imageUrl property to the src attribute and the temple's templeName property to the alt attribute.
Appends the
element, the two elements, and the
element to the element as children. Appends the element to the HTML element with an ID of temples.
Create another function called getTemples. Make it an async function.
In the function, using the built-in fetch method, call this absolute URL: 'https://byui-cse.github.io/cse121b-course/week05/temples.json'. Create a variable to hold the response from your fetch. You should have the program wait on this line until it finishes.
Convert your fetch response into a Javascript object ( hint: .json() ). Store this in the templeList variable you declared earlier. Make sure the the execution of the code waits here as well until it finishes.
Finally, call the output function and pass it the list of temples. Execute your getTemples function to make sure it works correctly.
Declare a function named reset that clears all of the elements from the HTML element with an ID of temples.
Declare a function named sortBy that:
calls the reset function,
sorts the global temple list by the currently selected value of the HTML element with an ID of sortBy, and
calls the output function passing in the sorted list of temples.
Add a change event listener to the HTML element with an ID of sortBy that calls the sortBy function.
Appends the
Create another function called getTemples. Make it an async function.
In the function, using the built-in fetch method, call this absolute URL: 'https://byui-cse.github.io/cse121b-course/week05/temples.json'. Create a variable to hold the response from your fetch. You should have the program wait on this line until it finishes.
Convert your fetch response into a Javascript object ( hint: .json() ). Store this in the templeList variable you declared earlier. Make sure the the execution of the code waits here as well until it finishes.
Finally, call the output function and pass it the list of temples. Execute your getTemples function to make sure it works correctly.
Declare a function named reset that clears all of the
Declare a function named sortBy that:
calls the reset function,
sorts the global temple list by the currently selected value of the HTML element with an ID of sortBy, and
calls the output function passing in the sorted list of temples.
Add a change event listener to the HTML element with an ID of sortBy that calls the sortBy function.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
