12311k

Untitled

May 2nd, 2020
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.08 KB | None | 0 0
  1. let phrases = [
  2. { text: 'отправить другу смешную гифку', image: 'https://code.s3.yandex.net/web-code/procrastinate/1.gif' },
  3. { text: 'посмотреть скидки на авиабилеты', image: 'https://code.s3.yandex.net/web-code/procrastinate/2.png' },
  4. { text: 'разобраться, о чём поют рэперы', image: 'https://code.s3.yandex.net/web-code/procrastinate/3.png' },
  5. { text: 'Юрий Дудь', image: 'https://code.s3.yandex.net/web-code/procrastinate/4.png' },
  6. { text: 'расставить книги на полке по цвету', image: 'https://code.s3.yandex.net/web-code/procrastinate/5.png' },
  7. { text: 'читать про зарплаты в Сан-Франциско', image: 'https://code.s3.yandex.net/web-code/procrastinate/6.png' },
  8. { text: 'прочитать новости и ужаснуться в комментариях', image: 'https://code.s3.yandex.net/web-code/procrastinate/7.png' },
  9. { text: 'попасть в поток грустных песен и вспомнить все ошибки молодости', image: 'https://code.s3.yandex.net/web-code/procrastinate/8.png' },
  10. { text: 'посмотреть трейлер сериала и заодно первый сезон', image: 'https://code.s3.yandex.net/web-code/procrastinate/9.png' },
  11. { text: 'проверить непрочитанное в Telegram-каналах', image: 'https://code.s3.yandex.net/web-code/procrastinate/10.png' }
  12. ];
  13.  
  14. function getRandomElement(arr) {
  15. let randIndex = Math.floor(Math.random() * arr.length);
  16. return arr[randIndex];
  17. }
  18.  
  19. let button = document.querySelector('.button');
  20. let phrase = document.querySelector('.phrase');
  21. let advice = document.querySelector('.advice');
  22. let image = document.querySelector('.image');
  23.  
  24. button.addEventListener('click', function () {
  25. let randomElement = getRandomElement(phrases);
  26. phrase.textContent = randomElement.text;
  27.  
  28. if (randomElement.text.length > 40) {
  29. advice.style.fontSize = '33px';
  30. } else {
  31. advice.style.fontSize = '42px';
  32. }
  33. });
Add Comment
Please, Sign In to add comment