Yuppi

funktio

Jun 6th, 2021
533
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function myQuote() {
  2.  
  3.     var input = document.getElementById("userInput").value;
  4.     var path;
  5.  
  6.     if (input === 'dota') {
  7.         path = 'dotapasta.txt';
  8.     } else if (input === 'ence') {
  9.         path = 'ence.txt';
  10.     } else if (input === 'muu') {
  11.         path = 'other.txt';
  12.     }
  13.  
  14.     fetch(path)
  15.         .then(result => result.text())
  16.         .then(result => {
  17.           const quotes = result.split('\n')
  18.  
  19.           //console.log(quotes)
  20.           var nLines = quotes.length;
  21.           var rngNum = Math.floor(Math.random() * nLines);
  22.           var randomLine = quotes[rngNum];
  23.  
  24.           console.log(randomLine);
  25.           document.getElementById("pasta").innerHTML = randomLine;
  26.  
  27.         })
  28.         .catch(error => console.error(error))
  29.    
  30.     document.write('End');
  31.  
  32. }
RAW Paste Data