still don’t get the if-functionality:
how can i get something like this working in ionic?
-> “each time the user loads a page, ionic should choose 3 given cities from a random cities-array”
This is not an Ionic related question, but a general programming one. Basically, your if statements are never called from the ionViewWillEnter function.
This is nothing personal against @ChrisGriiffith, who as usual has done a better job of coloring within the lines than I, but I have two fundamental philosophical quibbles with the code in the previous post (and OP, for that matter):
Store stuff in one canonical place
I get queasy when I write code that has overlapping responsibility, because it inevitably raises the question “what happens when they disagree?”, and in my experience that’s just a festering cauldron of bugs waiting to happen. So I don’t like the fact that RandomNumber is an object property alongside currentCities which derives from it. I want one or the other only.
Concise idioms improve readability
The big if/else chain obscures what is happening under the weight of verbosity. There is an opportunity here to make a choice between ease of data representation and brevity/simplicity of code. Especially in interpreted languages like JavaScript, I always choose to restructure data for the convenience of code.
This a great example of starting with code that works (mine), then refactoring it into something more concise (@rapropos). I could see the next step, taking this list of cities and migrating them into a service, and having it do the heavy lifting and not the page component.