[string].toUpperCase()
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
Name | Type | Required? | Description |
---|---|---|---|
string | string | The string to copy and convert to all upper case. |
Returns
Tips
- toLowerCase() copies and converts a string to all lower case.
Found a bug in the documentation? Let us know at support@code.org.