Self-Paced Work: Funktional Functions Updates
Follow these instructions to update the Funktional Functions website.
New Cycle Speed
Currently, when the color cycle is running, it changes colors once every 250 milliseconds. Update this to make it a little less hectic - try 500 milliseconds instead.
New Colors
Currently, there are only six colors for the filter. Add a few more colors to randomly cycle.
Note: to make the filter stronger or weaker, check the
.filter
ruleset in the style.css file, and update theopacity
value.
Play/Pause Button
Currently, the button text for the "🎸 ⏯" button is always the same. However, to make it more dynamic, update the code so that it changes the button text based on whether or not the music is playing. If the music is playing, it should display ⏸. If the music is not playing, it should display ▶.
- Open the script.js file for editing
- Find the
playBass
function - In the body of the
if
, underbassAudio.play()
, make a new line - There, set
playPauseBassButton.textContent
to"🎸 ⏸"
- In the body of the
else
, underbassAudio.pause()
, make a new line - There, set
playPauseBassButton.textContent
to"🎸 ▶"
Run the program, click the button, and make sure the play and pause symbols show up appropriately!
Display Current Filter Color
As of now, the filter color changes, but a visitor to the site might not know what the current color actually is. Add a piece of code to display the current color of the background filter.
HTML: A New Paragraph
Start by adding a new <p>
element in the HTML.
- Open the index.html file for editing
- Make a new line under the
<h1></h1>
- There, add a new
<p></p>
element - Set the
id
of the<p>
to be"filter-color"
JS: Setting the Paragraph Text
Next, update the <p>
element text every time the filter color changes.
- Open the script.js file for editing
- Make a new line under the
backgroundFilterDiv
variable initialization - There, create a new variable named
filterColorParagraph
- Set
filterColorParagraph
to a call todocument.querySelector
- Pass in
"#filter-color"
to store the proper<p>
element in the variable - Make a new line at the bottom of the
randomBgFilter
function - There, set
filterColorParagraph.textContent
to berandomColor
Run the program, start the cycle, and verify that the current filter color appears on the page!
Easter Egg: Header Click
Add a secret way to change the background image - when a site visitor clicks the "FUNKTIONAL FUNCTIONS" header, a new picture should appear!
- Open the script.js file for editing
- Make a new line at the bottom of the file
- There, Define a new function named
slyBackground
function
keyword- Function name (
slyBackground
) - Parentheses (
()
) - Curly brackets (
{}
)
- Make a new line in the body of the function (between
{
and}
) - There, set
document.body.style.backgroundImage
to"url('https://github.com/hytechclub/web-103/raw/main/Assets/sly.jpg')"
- This will change the background image of the page
- Make a new line under the function definition (after
}
) - There, create a new variable named
header
- Set
header
to select the"h1"
usingdocument.querySelector
- Under that, call
header.addEventListener
- Pass in
"click"
andslyBackground
to theaddEventListener
call
Run the program, click the header, and verify that the background changes!
Header Click Music
In addition to changing the background image, start playing a different piece of music when the header is clicked.
- Make a new line above the
slyBackground
function definition - There, create a new variable named
danceToTheMusic
- Set
danceToTheMusic
to be anew Audio
object - Set the audio file to be
"https://github.com/hytechclub/web-103/raw/main/Assets/dancetothemusic.mp3"
- Set
- Make a new line in the body of the
slyBackground
function - There, reate an
if
/else
structureif
keyword- Parentheses (
()
) - Curly brackets (
{}
) else
keyword- Curly brackets (
{}
)
- For the
if
condition, check ifdanceToTheMusic.paused
- In the body of the
if
, call thedanceToTheMusic.play
function - In the body of the
else
, call thedanceToTheMusic.pause
function
Run the program, click the header again, and verify that the new music can start and stop playing!