html
html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<!--
CHALLENGE: Counting And Display Strings
Write a program that captures a string that can contain spaces and displays each word in the string, the separator being the space.
Example, for the input: "I think so I am"
The program displays:
word 1: I
word 2: think
word 3: so
word 4: I
word 5: am
And finally it shows how many words the sentence has.
Good luck.
by Med Arezki Jr.
-->
<!DOCTYPE html>
<html>
<head>
<title>Word Count Challenge</title>
</head>
<body>
Enter to Rename, Shift+Enter to Preview
css
css
1
2
3
body {
}
Enter to Rename, Shift+Enter to Preview
js
js
1
2
3
var a = prompt("Enter your sentence:").split(/\s+/g), b = "";
for(var j=0; j<a.length; j++){ b+="word "+(j+1)+"= "+a[j]+"\n";}
alert(b+"Total: "+ a.length + " words.");
Enter to Rename, Shift+Enter to Preview
BROWSER
Console
Run