Created
August 31, 2013 10:31
-
-
Save nau/6397422 to your computer and use it in GitHub Desktop.
JScala supports ternary operator expressions.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val ast = javascript { | |
def main(args: Array[String]) { | |
val language = if (args.length == 0) "EN" else args(0) | |
val res = language match { | |
case "EN" => "Hello!" | |
case "FR" => "Salut!" | |
case "IT" => "Ciao!" | |
case _ => "Sorry, I can't greet you in " + language + " yet" | |
} | |
console.log(res) | |
} | |
} | |
println(ast.asString) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
function main(args) { | |
var language = (args.length == 0) ? "EN" : args[0]; | |
var res; | |
switch (language) { | |
case "EN": | |
res = "Hello!"; | |
break; | |
case "FR": | |
res = "Salut!"; | |
break; | |
case "IT": | |
res = "Ciao!"; | |
break; | |
default: | |
res = ("Sorry, I can't greet you in " + language) + " yet"; | |
break; | |
}; | |
console.log(res); | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment