Practice Real Company Assessment Patterns • Latest 2025–2026 Mock Tests

Programming Exercises

Implement a function to count the number of words in a string.

Medium

Problem Statement

Implement a function to count the number of words in a string.

Sample Input

"JavaScript is fun"

Sample Output

3

Limits

Time: 2s · Memory: 256 MB

Code Editor
00:00
// Count the number of words in a string function countWords(str) { } console.log(countWords("JavaScript is fun"));
Log in or sign up to run or submit your code.Log inSign up
Input
"JavaScript is fun"
Expected Output
3