Advertisement
sanjiisan

Untitled

May 13th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Zadanie1
  2. function mathInfo() {
  3.     var randomNumber = Math.floor(Math.random() * 100);
  4.  
  5.     console.log(randomNumber % 2 == 0, randomNumber);
  6.  
  7.     for (var i = 1; i <= Math.floor(randomNumber / 2); i++) {
  8.         if (randomNumber % i == 0) {
  9.             console.log(i, 'dzielnik');
  10.         }
  11.     }
  12.  
  13.     var res = randomNumber % 5;
  14.     console.log(Math.pow(randomNumber, res));
  15. }
  16.  
  17. mathInfo();
  18. /////
  19. Zadanie2
  20. function myEval(a, b, operation) {
  21.     var result = 0;
  22.     switch (operation) {
  23.         case'+':
  24.             result = a + b;
  25.             break;
  26.         case'-':
  27.             result = a - b;
  28.             break;
  29.         case'/':
  30.             result = a / b;
  31.             break;
  32.         case'*':
  33.             result = a * b;
  34.             break;
  35.         case'%':
  36.             result = a % b;
  37.             break;
  38.         case'^':
  39.             result = Math.pow(a, b);
  40.     }
  41.     return result;
  42. }
  43.  
  44. console.log(" 2 + 4 = " + myEval(2, 4, "+"));
  45. console.log(" 5 - 2 = " + myEval(5, 2, "-"));
  46. console.log(" 4 ^ 8 = " + myEval(4, 8, "^"));
  47. console.log(" 8 % 3 = " + myEval(8, 3, "%"));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement