Click here to Skip to main content
13,833,837 members
Rate this:
Please Sign up or sign in to vote.
See more:
I’m new to coding, and I mostly only know variables and booleans in swift.
I’ve been trying to code a pokemon-esqe thing, and here’s what it looks like:

Var charmander = “fire”
Var squirtle = “water”
Var bulbasaur = “grass”

“Water” > “fire”

Var battle1 = squirtle > charmander (true)

(The thing is, when I try to code the grass part, it returns false. Look.)

“water” < “grass” (false)
“grass” > “water” (false)

“fire” > “grass” (false)
“grass” < “fire” (false)

I need to get grass to work for the code to work the way I want, and it’s not working like this.

What I have tried:

I’ve tried both combinations of code (E.G. fire > grass and grass < fire), and have tried retyping “grass” in the initial variable, but it still doesn’t work! I don’t know wat to do.
Richard MacCutchan 13-Aug-18 3:27am
Look at those strings. "water" is always greater than "grass" in normal sort sequence.
Member 13946784 13-Aug-18 10:25am
How so?
Richard MacCutchan 13-Aug-18 10:57am
What do you mean by "how so"? They are alphabetic strings, so they will be compared alphabetically. So "grass" always comes before (is less than) "water".
Member 13946784 13-Aug-18 21:41pm
Oh, sorry. I’m just REALLY new to coding, and had no idea. Thank you for your answer!
Richard MacCutchan 14-Aug-18 3:23am
Spend some (a lot of) time learning the language and its rules. You cannot learn programming by posting questions in forums like this.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Cookies | Terms of Service
Web01 | 2.8.190114.1 | Last Updated 12 Aug 2018
Copyright © CodeProject, 1999-2019
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100