I am a complete beginner and have started to learn Kotlin via YouTube tutorials and Google searching for specifics.
When I was following a tutorial, he created three variables inside the MainActivity class as the following
class MainActivity : AppCompatActivity() {
var firstName= "David"
var secondName= "Tal"
var age = 20
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
}
Next, he uses the created variables in a private function like this:
private fun nameRating(){
if(firstName == secondName){
Toast.makeText(applicationContext,"10/10", Toast.LENGTH_LONG).show()
}else{
Toast.makeText(applicationContext,"5/10", Toast.LENGTH_LONG).show()
}}
I followed the example and recreated it in Android Studio, but the if condition triggered, and I thought it was weird. After debugging it turned out that both firstName and secondName are "0". I thought the variables were supposed to be global, and it is confusing why it is not working because the age variable is correct.
If I am completely wrong on how this should work, any explanation/clarification on the matter would be appreciated.