Skip to main content

Self review: Song selection - React Basic

Updated 1 min readMarkdown
Part of seriesReact Basics
Self review: Song selection - React Basic
  1. In plain JavaScript, how do you build an instance of the Audio constructor?

    • new Audio();

    • New Audio();

    • Audio();

  2. If an object instance of the Audio constructor is saved in a variable named “song”, what property on the “song” object can you use to check if the song is currently playing?

    • song.paused

    • song.pause();

    • song.play()

  3. What is wrong with this code?

     function toggle() {
         if(song.paused) {
             song.pause()
         } else {
             song.play()
         }
     }
    
    • The app's logic doesn't work. The code on line 3 and the code on line 5 should swap places.

    • The condition in the if statement is wrong. It should be:

      if(song.paused())

    • You need to have an else if condition, in between the if and else conditions.

About the author

No comments yet. Be the first to comment.

React Basics

Part 2 of 18

In this module you will explore the basic structure and use of the React.js library. You will learn how to produce single page web applications using React components and to use JSX to style them.

Up nextSelf review: Displaying images - React BasicIs this code a correct way to import an image in React? import avatar from "./assets/avatar.png" function UserImage() { return ( <div> <img src={avatar} alt = "User image" /> < /di...

More from this blog