//wow this practice is awesome and hard and intense, it's great!
//Main function
function main() {
var input = readLine();
var wordCount = print(countWords(input));
var ranLetter = randomLetter();
var randomLetterCount = print(countWordsWith(input, ranLetter));
letterFrequency(input);
}
function randomLetter() {
var alpha = "a b c d e f g h i j k l m n o p q r s t u v w x y z";
var alphaArr = alpha.split(" ");
var randomN = Math.floor(Math.random() * 25);
var randomLetter = "";
for (var i = 0; i < alphaArr.length; i++) {
if (i == randomN) {
randomLetter = alphaArr[i];
return randomLetter;
}
}
}
function countWords(text) {
var arr = text.split(" ");
var arrLength = arr.length;
return "Your input text has " + arrLength + " words.";
}
function countWordsWith(text, letter) {
var letterCount = 0;
var textLetterSplit = text.split("");
//print(textLetterSplit);
for (var i = 0; i < textLetterSplit.length; i++) {
if (textLetterSplit[i].includes(letter)) {
letterCount++;
}
}
return "There are " + letterCount + " with the randomly selected letter " + letter + ".";
}
function letterCount(textArr,alphaLoopLetter) {
var count = 0;
for(var i=0; i<textArr.length; i++) {
if(textArr[i] == alphaLoopLetter) {
count++;
}
}
//loop through the length of the text
//if each letter matches the input letter, increase the count.
return count;
}
function letterFrequency(text) {
var output = [];
var alphabet = "abcdefghijklmnopqrstuvwxyz";
var alphaArr = alphabet.split("");
var textLetterSplit = text.toLowerCase().split("");
for(var i = 0; i < alphaArr.length; i++) {
print(alphaArr[i] + ": " + letterCount(textLetterSplit, alphaArr[i]));
}
//loop through all 26 letters in the alphabet
//use letter count(text, whatever letter youre on)
//store that number into the output array
}
function multipleVision(string, n) {
var output = "";
for (var i...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.