Advertisement
biswasrohit20

java medal

Mar 12th, 2021
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. # Bronze
  2.  
  3. var rand;
  4. function gimmeRandom(){
  5. rand = Math.floor(Math.random()*10) +1;
  6. }
  7. gimmeRandom();
  8. console.log("The random number is " + rand);
  9.  
  10.  
  11. # Silver
  12.  
  13. var count = 0;
  14. var rand;
  15. function gimmeRandom() {
  16. rand = Math.floor(Math.random() * 10) + 1;
  17. count++;
  18. }
  19.  
  20.  
  21. function countToRandom() {
  22. for (var count = 1; count <= rand; count++){
  23. console.log(count);
  24. }
  25. }
  26.  
  27. console.log("Counting to a random number");
  28. gimmeRandom();
  29. countToRandom();
  30. console.log("Counting to another random number");
  31. gimmeRandom();
  32. countToRandom();
  33. console.log("There has been " + count + " random numbers");
  34.  
  35.  
  36. # Gold
  37.  
  38. var count = 0;
  39.  
  40. function gimmeRandom() {
  41. var rand = Math.floor(Math.random() * 10) + 1;
  42. count++;
  43. return rand;
  44. }
  45.  
  46.  
  47. function countToRandom(rand) {
  48. for (var count = 1; count <= rand; count++){
  49. console.log(count);
  50. }
  51. }
  52.  
  53. console.log("Counting to a random number");
  54. countToRandom(gimmeRandom());
  55. console.log("Counting to another random number");
  56. countToRandom(gimmeRandom());
  57. console.log("There has been " + count + " random numbers");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement