Relation of Elements JavaScript

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Relation of Elements</title>
</head>
<body>
  <h1>Relation of Elements</h1>
  <button onclick="generateRandomSentence()">Explore</button>
  <p id="result"></p>

  <script>
    function generateRandomSentence() {
      const buildingElements = ['door', 'furniture', 'window', 'facade', 'balcony', 'corridor', 'hearth', 'escalator', 'elevator', 'roof', 'wall', 'floor', 'ceiling', 'staircase', 'room',];
      const prepositions = ['à la','aboard','about','above','according to','across','after','against','ahead of','along','along with','alongside','amid ','among ','anti','apart from','around','as','as for','as per','as to','as well as','aside from','astride','at','atop','away from','barring','because of','before','behind','below','beneath','beside','besides','between','beyond','but','but for','by','by means of','circa','close to','concerning','considering','contrary to','cum','depending on','despite','down','due to','during','except','except for','excepting','excluding','following','for','forward of','from','further to','given','in','in addition to','in between','in case of','in favor of','in front of','in lieu of','in spite of','in the face of','in view of','including','inside','instead of','into','irrespective of','less','like','minus','near','near to','next to','notwithstanding','of','off','on','on account of','on behalf of','on board','on top of','onto','opposite','opposite to','other than','out of','outside','outside of','over','owing to','past','pending','per','plus','preparatory to','prior to','pro','re','regarding','regardless of','respecting','round','save (formal)','save for','saving (formal)','since','than','thanks to','through','throughout','till','to','together with','touching','toward','under','underneath','unlike','until','up','up against','up to','up until','upon','versus','via','vis-a-vis','with','with reference to','with regard to','within','without','worth'];

      const randomBuildingElement1 = buildingElements[Math.floor(Math.random() * buildingElements.length)];
      let randomBuildingElement2 = buildingElements[Math.floor(Math.random() * buildingElements.length)];

      while (randomBuildingElement1 === randomBuildingElement2) {
        randomBuildingElement2 = buildingElements[Math.floor(Math.random() * buildingElements.length)];
      }

      const randomPreposition = prepositions[Math.floor(Math.random() * prepositions.length)];

      const randomSentence = `${randomBuildingElement1} ${randomPreposition} ${randomBuildingElement2}`;
      
      document.getElementById('result').innerText = randomSentence;
    }
  </script>
</body>
</html>
Published

Leave a comment