Skip to content
UNWIND Code Lab Co-funded by the European Union
Strings and Arrays
Log In

Strings and Arrays

  • 5 min reading
  • 6 min activity
0 of 5 tasks doneup to 95 XP
  1. Quick recall10 XPOptional
  2. Code and result15 XPTo do
  3. Welcome panel30 XPTo do
  4. Counting from 010 XPTo do
  5. Fruit list30 XPTo do

Mission 4, step 4. Most of what people see on a website is text. Today you shape text and keep many values in one list.

In this lesson
  • Measure, change and search text with string methods.
  • Build a message with a template literal.
  • Make an array, read and change its items, and count them.
Remember

In lesson 4.3 you met the operator %. One quick question.

Quick check

Quick recall

10 XP

Tools for text

Every string has ready-made tools. .length is a property, so it has no brackets. The others are methods: they do something and need ().

CodeResult
"Hello world".length (spaces count too)11
"Lena".toUpperCase(), toLowerCase() the opposite"LENA"
"Learning JavaScript is fun.".indexOf("fun") (from 0; -1 = not found)23
"2026-01-20".slice(0, 4) (from 0 up to 4, without 4)"2026"
"apple apple".replace("apple", "pear") (first match only; replaceAll() changes all)"pear apple"

On the slice() slide, console.log(year); stands inside the comment, so nothing prints. After //, the rest of the line is a comment: give every statement its own line. Some languages have their own capitals: for Turkish, use toLocaleUpperCase("tr-TR").

Matching

Code and result

Required 15 XP

Template literals

A template literal is text in backticks. Inside it, ${ } puts a value into the text, without + and many quotes. On a phone keyboard, the backtick is often on the second page of symbols.

let name = "Ayla";
let age = 25;
console.log("My name is " + name + " and I am " + age + ".");
console.log(`My name is ${name} and I am ${age}.`);   // the same text

Worked example: a welcome panel

Fictional example

Eleni Demir logs in to a learning site. The site gets her data in small letters and builds a friendly welcome.

Worked example
  1. Tidy the data

    firstName.toUpperCase() turns "eleni" into "ELENI". The same for the last name and the city.

  2. Build the message

    One template literal puts the values into the text. It can go over several lines.

  3. Count

    ${first.length + last.length} adds the letters of both names: 5 + 5 = 10.

The slide calls this number the length of "your user name", but it counts first name plus last name.

Practice

Welcome panel

Required 30 XP

The daily application from the course slides: tidy the data, then build the welcome message. Choose the right piece for every gap.

Arrays

An array keeps many values in one box, in square brackets. Each item has a number, its index. Counting starts at 0.

fruits[0] fruits[1] fruits[2] fruits[3] Apple Pear Banana Strawberry Counting starts at 0. fruits.length is 4.
An array with four items. The first item has the index 0.
let fruits = ["Apple", "Pear", "Banana", "Strawberry"];
console.log(fruits[0]);       // Apple
fruits[1] = "Kiwi";           // Pear is gone, Kiwi is in its place
console.log(fruits.length);   // 4
let mixed = ["Ayla", 25, true, null];   // types can mix
Quick check

Counting from 0

Required 10 XP
Practice

Fruit list

Required 30 XP

Slides 45 to 48 of the course in one exercise: read, change and count the items of an array.

Method
A ready-made tool that does something, like toUpperCase().
Property
A value that belongs to something, like .length. No brackets.
Template literal
Text in backticks with values inside ${ }.
Array and index
A list in square brackets; the index is the number of an item, from 0.

In short

  • .length counts, toUpperCase() changes letters, indexOf() searches, slice() cuts, replace() changes.
  • A template literal puts values into text: `Hello, ${name}!`.
  • fruits[0] is the first item; fruits.length is the number of items.
Next time

Your code makes decisions: if this, then that.

Sources

  1. MDN Web Docs (2026). Useful string methods.
  2. MDN Web Docs (2026). Template literals (Template strings).
  3. MDN Web Docs (2026). Arrays.
  4. MDN Web Docs (2026). String.prototype.toLocaleUpperCase().

End of the lesson

This lesson: 0 of 105 XP

Code Cards in this lesson: 8

  • .length
  • toUpperCase()
  • indexOf()
  • slice()
  • replace()
  • `${ }`
  • array
  • array[i]