0

My purpose is to run play() function first, then pause() function. The last code document.write("</br>You should really pass on the second"); just to test all the code run or not (if it display, the code run ok, right ?).

<!DOCTYPE html>
<html>
<head>
<title>c5vd4</title>
<meta charset="utf-8">
<script type="text/javascript">
var song = {
    name: "Walk This Way",
    artist: "Run-D.M.C.",
    minutes: 4,
    seconds: 3,
    genre: "80s",
    playing: false,
    play function() {
    if (!this.playing) {
    this.playing = true;
    document.write("Playing "+ this.name + " by " + this.artist);
        }
    },
    pause function() {
    if (this.playing) {
    this.playing = false;
    }
    }
}    
song.play();
song.pause();
document.write("</br>You should really pass on the second");
  </script>
  </head>
  </html>

But, when I ran my code, nothing display. Even the last code. Could you please give me some ideas for me with this problem ? Thank you very much.

2
  • What does your browser console say? You can use the F12 button in most modern browsers to display developer tools which allow you to see the console and any error messages in the page. I can see a couple of typos in your JavaScript code, the play and pause properties in your song object are missing colons (:). Commented Jun 16, 2021 at 2:05
  • @Hoppeduppeanut : Thank you for your comment, my console said at line 15 there was an error "Uncaught SyntaxError: Unexpected token 'function'" and when I read all your comments I understood why I had that error. Commented Jun 16, 2021 at 9:15

1 Answer 1

1

You need to use : with pause and play like:

var song = {
  name: "Walk This Way",
  artist: "Run-D.M.C.",
  minutes: 4,
  seconds: 3,
  genre: "80s",
  playing: false,
  play: function() {
    if (!this.playing) {
      this.playing = true;
      document.write("Playing " + this.name + " by " + this.artist);
    }
  },
  pause: function() {
    if (this.playing) {
      this.playing = false;
    }
  }
}
song.play();
song.pause();
document.write("</br>You should really pass on the second");

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.