str.toLowerCase

Category:Variables

[string].toLowerCase()

Category: Variables

Returns a new string that is the original string converted to all lower case letters.

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


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

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 fruitLower=fruit.toLowerCase();
  if (fruitLower == "apple") write(fruit + " is red");
  else if (fruitLower == "banana") write(fruit + " is yellow");
  else if (fruitLower == "orange") write(fruit + " is orange");
  else write("sorry I do not know ." + fruit);
});

Syntax

[string].toLowerCase()

Parameters

Name Type Required? Description
string string Yes The string to copy and convert to all lower case.

Returns

A copy of the string converted to all lower case.

Tips

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

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