Guest User

Untitled

a guest
Jun 18th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. // Variable for shaking the asciiart
  2. var shaking = false
  3. // Answer array
  4. var answers = ['Yes', 'Most certainly', 'Definitely', 'Count on it',
  5. 'No', 'Not in your wildest dreams', 'No way!', 'Sorry, no',
  6. 'Maybe', 'Possibly', 'Who knows', 'The future is cloudy',
  7. 'Why ask me?'
  8. ]
  9. // How many times will we shake the ball? Between 4 and 16 times
  10. shakeTimes = 4 + Math.floor(Math.random()*13)
  11.  
  12. // this shows the ball in 'up' or 'down' position
  13. function show8Ball() {
  14. console.clear()
  15. if (shaking) {console.log('\n')}
  16. console.log( '\
  17. \n .-"""-.\
  18. \n/ _ \\\
  19. \n\| (8) |\
  20. \n\\ ^ /\
  21. \n \'-...-\'\
  22. ')
  23. shaking = !shaking }
  24.  
  25. //show the ball a given number of times, then show answer
  26. function shakeTheBall(times) {
  27. for (i = 0; i < times; i++) {
  28. setTimeout(function() {
  29. show8Ball();
  30. } , 500*i)
  31. }
  32. setTimeout(function() {
  33. console.clear()
  34. console.log(getAnswer())
  35. }, 500*times)
  36. }
  37.  
  38. //return the answer we get
  39. function getAnswer() {
  40. var whichAns = Math.floor(Math.random() * answers.length)
  41. return answers[whichAns]
  42. }
  43.  
  44. // "Hi, I'm running for you'
  45. console.log('Magic 8 ball shaking!')
  46. // and in a bit, we will shake it
  47. setTimeout(function() {shakeTheBall(shakeTimes)}, 1000)
Add Comment
Please, Sign In to add comment