Javascript poem-generator - matching a substring with any single element in an array

I had no idea how to write this question, because it is a multi-stage question!

Some background: I am trying to combine my background in English literature and grammar, about my love for "face divorced" memo poems and about my growing knowledge of javascript to create a lik the bred poem generator.

In principle, the user enters a one-word name / noun, and a rhyme poem will be created based on this word. The logic for this first bit is as follows:

  • Step One: Get User Input
  • Step Two: Find out how long user input (this step may not be needed)
  • Step Three: Find the first vowel (including only "y" if it is the only vowel - alternatively, include only "y" if this is the last letter)
  • Fourth step: select all letters, including after that. vowel
  • Step Five: Compare these letters with possible end rhymes.

The problem is that I'm not sure how to handle steps three and four. (I am open to solutions using jQuery or javascript libraries, but since I'm still a beginner, I did not attach much importance to writing anything other than direct javascript from scratch.

NB: If the upper limit for length is useful, nine characters will make sense, since the longest monosyllables in English are 9 letters long.

My first thought was to make a conditional statement, for example:

var noun = document.getElementById('noun').value; // noun input by user
var n = noun.str.length; // length of unknown word
var place = 0
var firstVow; // location of first vowel
while (place < 10) { 
// can you even do nested while loops/conditionals like this?
    if (noun.charAt(place) == 'a' ||
        noun.charAt(place) == 'e' ||
        noun.charAt(place) == 'i' ||
        noun.charAt(place) == 'o' ||
        noun.charAt(place) == 'u'|| 
        noun.charAt(n) == 'y') {
           firstVow = noun.indexOf(place);}
    else {
        place++;
    }
}
 var numSel = n - firstVow; // number of characters to select equals string length minus location of the first vowel
 var nounSel = noun.substr(firstVow, numSel); // selection to compare to end-rhymes

( , ... , , ), , a/e/i/o/u/word-terminal-y, ... .

, , ( ), , ). , , , ? , .

!

:

, " ":

  • "ay", "": [ay, eigh, ei]
  • "i", "": [y, eye, aye, ye]
  • "", "": [a, ah, aw]
  • "ot" , "": [ot, ott, shouldugh, aught]

:

  • : : ""
  • 1: [: "" ]
  • 2: [: 5 , aka 0-4] ​​
  • 3: [: "o" 2]
  • 4: [: "ott" ]
  • 5: / (: "ot" )
  • 6: 3, 5 7 "ot" [NB: , ]

"ott" . , :

var ay = ["ay", "eigh", "ei"];
var eye = ["y", "eye", "aye", "ye"];
var ah = ["a", "ah", "aw"];
var ot = ["ot", "ott", "ought", "aught"];

, ? , ?

+4
1

, , , , y, , , .

function getEnding(word) {
    return (word.match(/[aeiou]*[aeiouy]$|[aeiou]+[^aeiou]+$/) || [''])[0];
}

console.log(['scott', 'bay', 'by', 'saw', 'bot', 'uncaught'].map(getEnding));
Hide result
+1

Source: https://habr.com/ru/post/1689665/


All Articles