Skip to content

Count uppercase letters

JavaScript loop + condition

Flowchart (ISO 5807)

YesNoStartInput scount = 0i = 0, |s| − 1, 1c = s[i]c ≥ «A» and c ≤ «Z»count = count + 1Return countEndFigure 1 — countUpper

Source code

JavaScript
function countUpper(s) {
    let count = 0;
    for (let i = 0; i < s.length; i++) {
        const c = s[i];
        if (c >= "A" && c <= "Z") {
            count++;
        }
    }
    return count;
}

The editor opens with this code — change it and the chart redraws.

Language
JavaScript
Constructs
loop + condition
Topic
Loops
Formats
Word, Visio, draw.io, PDF, SVG

Related examples