Game Lab Documentation

[string].toUpperCase()

Category:Variables

Sometimes in a text processing app you need to convert all the letters in a message to be the same case, all lower or all upper case. This can make it easier to match keywords your app is looking for to text input by the user, without having to worry about what case the letters are.

Examples

Example: a string and a variable

// Convert a string and variable containing a string to upper case.
console.log("Hello World".toUpperCase());
var computingPioneer="Ada Lovelace";
console.log(computingPioneer.toUpperCase());

Example: colors of fruits

Demonstrate matching keywords to user input regardless of case.

// Demonstrate matching keywords to user input regardless of case.
textLabel("fruitLabel","Fruit Name");
textInput("fruitInput","");
onEvent("fruitInput", "change", function(event) {
  var fruit=getText("fruitInput");
  var fruitUpper=fruit.toUpperCase();
  if (fruitUpper == "APPLE") write(fruit + " is red");
  else if (fruitUpper == "BANANA") write(fruit + " is yellow");
  else if (fruitUpper == "ORANGE") write(fruit + " is orange");
  else write("sorry I do not know ." + fruit);
});

Syntax

[string].toUpperCase()

Parameters

NameTypeRequired?Description
stringstring

The string to copy and convert to all upper case.

Returns

A copy of the string converted to all upper case.

Tips

Found a bug in the documentation? Let us know at support@code.org.