Advertisement
Guest User

Untitled

a guest
Aug 21st, 2019
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.68 KB | None | 0 0
  1. /*
  2. * The FocusMiss Script
  3. * If you have ever played competetive pokemon and used a low accuracy move such as
  4. * Focus Blast or Stone Edge, it always seems to miss at the worst times possible,
  5. * or even worse just never hit. This script plays off of that concept.
  6. * I want you to build on this template that I have written and calculate how many times
  7. * Focus Blast (or another Pokemon move with 70 accuracy or less) hits in a row.
  8. * To make this assignment work, you would need to use some JavaScript code that
  9. * you have not learned yet, as a result I have written a small function for you
  10. * that handles the parts that you have not learned yet. Please see the comment
  11. * above the function for details about how it works. Once you have calculated how many
  12. * times your move has hit before missing, log that result to the console, perferebly
  13. * in a nice string such as "MOVENAME hit HITS time(s) before missing!".
  14. *
  15. * HINTS:
  16. * Your result will vary each time due to the randomness of a move hitting or missing.
  17. * Remember DRY (Don't Repeat Yourself).
  18. * A for loop will not work here, there is a different kind of loop that will work for this.
  19. *
  20. * After you complete the assignment please turn it into me so I can ensure you understood
  21. * today's concepts and offer feedback in areas you could improve in. When turning this in
  22. * fill out the following info (only discord tag is required):
  23. *
  24. * Discord Tag: Anubis#2855
  25. * Pokemon Showdown Username: Anubis
  26. * Twitch Username: tverbloem
  27. */
  28. 'use strict';
  29.  
  30. /*
  31. * This is a function, you don't know what they do yet but it will help you
  32. * during this assignment. I will treat this like console.log and just teach you
  33. * how to use it, not how it works. To run it, you need to type runMove(accuracy),
  34. * however you need to replace "accuracy" with a number that represents the accuracy
  35. * of the move you are trying to see will hit. The function will return a value,
  36. * meaning that if you assign a variable to runMove(accuracy), the function will
  37. * determine its value. The function wil randomly return either true if the move
  38. * hit, or false if it missed. The function also only calculates one attempted
  39. * move at a time. If you need to do more than one, write code to run the
  40. * function more than once.
  41. */
  42. function runMove(accuracy = 70) {
  43. // I flipped the sign in this function because it was returning true for misses.
  44. return Math.floor(Math.random() * 100) < accuracy;
  45. }
  46.  
  47. // Your code under this line
  48. let hits = 0;
  49. /* We're not really optimistic enough that this will hit infinitely, right? If
  50. * we are, we can always set a maximum number of hits. */
  51. while (runMove() && hits < 1000)
  52. hits++;
  53. console.log(`Focus Blast hit ${hits} time(s) before missing!`);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement