Reputation: 117
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.
Upvotes: 0
Views: 35
Reputation: 8162
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");
Upvotes: 1