Loops - Exercise 3

Question 1: Reverse Characters with a Loop

Return the supplied ASCII string with its characters reversed using a loop.

Expected output: "edoc" (print this with console.log)

javascript

function reverseAsciiWithLoop(text) {
  // Write your solution here
}

console.log(reverseAsciiWithLoop("code"));

Question 2: Count Uppercase ASCII Letters

Return the count of uppercase English letters A through Z in the supplied string.

Expected output: 3 (print this with console.log)

javascript

function countUppercaseAsciiLetters(text) {
  // Write your solution here
}

console.log(countUppercaseAsciiLetters("Hi JS!"));

Question 3: Extract Digits from Text

Return the ASCII digits in the input string in their original order.

Expected output: "123" (print this with console.log)

javascript

function extractAsciiDigits(text) {
  // Write your solution here
}

console.log(extractAsciiDigits("a1b23"));

Question 4: Count ASCII Vowels

Count English vowels a, e, i, o, and u in the supplied text, ignoring case.

Expected output: 2 (print this with console.log)

javascript

function countAsciiVowels(text) {
  // Write your solution here
}

console.log(countAsciiVowels("Hello"));

Question 5: Find the First Space

Return the index of the first space character, or -1 if the string has no spaces.

Expected output: 5 (print this with console.log)

javascript

function firstSpaceLoopIndex(text) {
  // Write your solution here
}

console.log(firstSpaceLoopIndex("hello world"));

Question 6: Alternate ASCII Letter Case

Return an ASCII string where characters at even indices are uppercase and characters at odd indices are lowercase.

Expected output: "HeLlO" (print this with console.log)

javascript

function alternateAsciiCase(text) {
  // Write your solution here
}

console.log(alternateAsciiCase("hello"));

Question 7: Join Words with a Loop

Join an array of strings using a hyphen between entries and no trailing hyphen.

Expected output: "red-blue-green" (print this with console.log)

javascript

function joinWordsWithLoop(words) {
  // Write your solution here
}

console.log(joinWordsWithLoop(["red","blue","green"]));

Question 8: Count Consecutive Spaces

Return the length of the longest run of consecutive space characters in the input.

Expected output: 3 (print this with console.log)

javascript

function longestSpaceRun(text) {
  // Write your solution here
}

console.log(longestSpaceRun("a  b   c"));

Question 9: Find the Last Digit

Return the last ASCII digit in the string, or null if none exists.

Expected output: "7" (print this with console.log)

javascript

function lastAsciiDigit(text) {
  // Write your solution here
}

console.log(lastAsciiDigit("x2y7z"));

Question 10: Remove Spaces with a Loop

Return the input string without any space characters. Other whitespace is unchanged.

Expected output: "abc" (print this with console.log)

javascript

function removePlainSpaces(text) {
  // Write your solution here
}

console.log(removePlainSpaces("a b  c"));