+ 1

Am having this error, unresolved reference: play, on MusicPlayer. My code below On Kotlin

class MusicPlayer { private var songs: Array<String> = arrayOf("Purple Haze","Under Pressure","Walk This Way","Playing Purple Haze","Stop") //your code goes here fun add(track: String): Unit{ songs += track } fun show(){ println("$songs[0]\n$songs[1]\n$[2]\n$songs[3]") } fun pay(){ val play = songs println("$songs[0]") } } fun main(args: Array<String>) { val m = MusicPlayer() while(true) { var input = readLine()!! if(input == "stop") { break } m.add(input) } m.show() m.play() }

5th Mar 2021, 4:32 AM
Dave Enyi
Dave Enyi - avatar
10 Answers
+ 3
Dave Enyi Did you name the function pay() in error? Did you mean to name it play()
5th Mar 2021, 5:24 AM
Paul K Sadler
Paul K Sadler - avatar
+ 3
Dave Enyi congrats you did itšŸ‘šŸ‘
7th Mar 2021, 10:35 AM
ā¤ļøšŸ˜PreranašŸ˜ā¤ļø
ā¤ļøšŸ˜PreranašŸ˜ā¤ļø - avatar
+ 3
Dave Enyi Good work!
7th Mar 2021, 12:48 PM
Paul K Sadler
Paul K Sadler - avatar
+ 2
Hi Dave Enyi I couldn't get any of your functions to work. I suggest you work on one aspect of the code at a time, comment out the other calls. Remember, you either need to return from a function, or print the result. fun add() does nothing at the moment. Also, check your types, and you may wish to use a loop in your fun show() because the tests will have a varied number of songs. Good luck
5th Mar 2021, 11:08 AM
Rik Wittkopp
Rik Wittkopp - avatar
+ 2
You should try this : class MusicPlayer { private var songs: Array<String> = arrayOf() //your code goes here fun add(name:String){ songs += name } fun show(){ songs.forEach(){ item -> println(item) } } fun play(){ println("Playing "+ songs[0]) } } fun main(args: Array<String>) { val m = MusicPlayer() while(true) { var input = readLine()!! if(input == "stop") { break } m.add(input) } m.show() m.play() }
6th Mar 2021, 11:34 PM
ā¤ļøšŸ˜PreranašŸ˜ā¤ļø
ā¤ļøšŸ˜PreranašŸ˜ā¤ļø - avatar
+ 2
Dave Enyi Congrats Well done!
7th Mar 2021, 9:32 AM
Rik Wittkopp
Rik Wittkopp - avatar
+ 1
Thanks
5th Mar 2021, 6:31 PM
Dave Enyi
Dave Enyi - avatar
+ 1
My final code up and running thank you so much guyz much love šŸ˜ I really appreciate you all for your support class MusicPlayer { private var songs: Array<String> = arrayOf() //your code goes here fun add(track: String): Array<String>{ songs = songs + track return songs } fun show(){ for(track in songs.indices){ println(songs[track]) } } fun play(){ println("Playing "+songs[0]) } } fun main(args: Array<String>) { val m = MusicPlayer() while(true) { var input = readLine()!! if(input == "stop") { break } m.add(input) } m.show() m.play() }
7th Mar 2021, 8:54 AM
Dave Enyi
Dave Enyi - avatar
0
Yes and is throwing an error message saying unresolved reference: play
5th Mar 2021, 9:27 AM
Dave Enyi
Dave Enyi - avatar
0
// here is the complete code but the play() is not working class MusicPlayer { private var songs: Array<String> = arrayOf("Purple Haze","Under Pressure","Walk This Way","Playing Purple Haze","Stop") //your code goes here fun add(track: String): Unit{ songs += track } fun show(){ println(songs[0]) println(songs[1]) println(songs[2]) println(songs[3]) } fun play(){ } } fun main(args: Array<String>) { val m = MusicPlayer() while(true) { var input = readLine()!! if(input == "stop") { break } m.add(input) } m.show() m.play() }
5th Mar 2021, 10:04 AM
Dave Enyi
Dave Enyi - avatar