Improving the Guide Page
Introduction: Why Improve the Guide Page?
Welcome back! So far, you have built a step-by-step cooking guide page that lets users follow recipes one step at a time. You have already added basic navigation, some interactivity, and styling. In this lesson, we will focus on making the guide page even more helpful and enjoyable for users.
Why do these improvements matter? When someone is cooking, they want the process to be smooth and easy. Features like keyboard shortcuts, and recipe ratings can make a big difference. They help users stay on track, move through steps quickly, and share feedback on recipes. By the end of this lesson, you will know how to add these features to your guide page.
Quick Recap: What the Guide Page Can Already Do
Before we dive into the new features, let’s quickly remind ourselves of what you have already built:
- The guide page loads recipe steps from the server.
- Users can move between steps using "Prev" and "Next" buttons.
- The page uses
JavaScriptto update the step text and handle navigation. - There is some basic styling to make the page look nice.
All of these features are already in place. In this lesson, we will build on top of them, so you do not need to change anything that is already working.
Making Navigation Easier with Keyboard Shortcuts
First, let’s make it easier for users to move through the recipe steps and play instructions using their keyboard. This is especially helpful if their hands are messy from cooking!
Listening for Key Presses
We add an event listener for keyboard events:
- When the user presses the Space bar, the current step is read aloud.
- Right Arrow moves to the next step (if possible).
- Left Arrow moves to the previous step (if possible).
Explanation:
e.preventDefault();stops the browser from performing its default action (like scrolling).playTTS();plays the text-to-speech for the current step.nextBtn.click();andprevBtn.click();simulate clicking the navigation buttons.
