// Input sentence
const sentence = 'This is a sample sentence.';
// Calculate word count by splitting the sentence at spaces
const wordCount = sentence.split(' ').length;
// Display the word count
console.log('Word Count:', wordCount);JavaScript Word Count in a Sentence
javascript
Related Posts
More content you might like
Tutorial
javascript
Primitive Data Types
let name = "Alice";
let greeting = 'Hello';
let message = `Welcome, ${name}!`; // Template literal
console.log(message); // "Welcome, Alice!"The number type represents both integers and floating-point numbers.
Dec 11, 2024
Read More Code
javascript python +1
Generate Random Password
No preview available for this content.
Jan 26, 2024
Read More Code
javascript python
Reversing a String in JavaScript: A Simple Guide
No preview available for this content.
Jan 26, 2024
Read MoreDiscussion 0
Please sign in to join the discussion.
No comments yet. Be the first to share your thoughts!