zamaro

JS5

Dec 11th, 2021
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.46 KB | None | 0 0
  1. // Exercise A
  2.  
  3. // Task 1. two int. which is largest
  4. let num1 = 1;
  5. let num2 = 2;
  6. let num3 = 3;
  7.  
  8. let largest = Math.max(num1, num2, num3);
  9.  
  10. console.log("The largest number is " + largest);
  11.  
  12. //Task 2. two int, check if they divide each other
  13.  
  14.  
  15.  
  16. function divtest(variable1, variable2) {
  17. variable1 = prompt("Enter a Value to check if divisible");
  18. variable2 = prompt("Enter a Value to check if divisible");
  19. varin1 = parseInt(variable1);
  20. varin2 = parseInt(variable2);
  21. if (varin1 % varin2 === 0) {
  22. console.log("Number 1 is divisible by number 2 ");
  23. } else if (varin2 % varin1 === 0) {
  24. console.log("Number 2 is divisible by number 1");
  25. } else {
  26. console.log("No Number can Divise the other/improper input");
  27. }
  28. }
  29.  
  30. // this runs the function .. you can input any number and try!
  31. divtest();
  32.  
  33.  
  34. //Task 3. Two int, show the larger then smaller number
  35.  
  36. function checkLarger(Numbers1, Numbers2) {
  37. Numbers1 = prompt("Enter the first of two Numbers to check who's bigger")
  38. Numbers2 = prompt("eEnter the second of two Numbers to check who's bigger")
  39. if (Numbers1 == Numbers2) {
  40. console.log("Error, Numbers are the same!");
  41. } else if (Numbers1 > Numbers2) {
  42. console.log("Number 1 is bigger!"); }
  43. else if (Numbers1 < Numbers2) {
  44. console.log("Number 2 is bigger!"); }
  45. else {
  46. console.log("this is not possible");
  47. }}
  48. checkLarger();
  49.  
  50.  
  51. // task 4. One Int, boolean true, false or zero according to its value.
  52. // הלכתי על מספר רנדומלי
  53.  
  54. // originalNumber = Math.random() === 0 ? -1 : 1;
  55.  
  56. function checkValuenumber(originalNumber) {
  57. originalNumber = Math.floor(Math.random() * 3) - 1 ; // this will get a number between 1 and 3 including zero;
  58. originalNumber *= Math.round(Math.random()) ? 1 : -1; // this adds negative, including zero.
  59. Math.sign(originalNumber);
  60. console.log(originalNumber);
  61. if (Math.sign(originalNumber) === 1){
  62. console.log("True, I'm positive");
  63. } else if (Math.sign(originalNumber) === -1) {
  64. console.log("False, I'm negative");
  65. } else if (Math.sign(originalNumber) === 0 ){
  66. console.log("I must be Zero");
  67. }else {
  68. console.log("I must not be a number");
  69. }
  70. }
  71. checkValuenumber();
  72.  
  73. // Task 5 Int from 1 to 10, show its name and if its out of range show error
  74.  
  75.  
  76.  
  77. function rangeofNumber() {
  78.  
  79. arrs1 = [' ','one ','two ','three ','four ',
  80. 'five ','six ','seven ','eight ','nine ','ten '];
  81. arrs2 = [1,2,3,4, 5, 6, 7, 8, 9, 10];
  82.  
  83. minarrs = arrs2[1];
  84. maxarrs = arrs2[10];
  85.  
  86. arrs2[1] = (arrs1[1]);
  87. arrs2[2] = (arrs1[2]);
  88. arrs2[3] = (arrs1[3]);
  89. arrs2[4] = (arrs1[4]);
  90. arrs2[5] = (arrs1[5]);
  91. arrs2[6] = (arrs1[6]);
  92. arrs2[7] = (arrs1[7]);
  93. arrs2[8] = (arrs1[8]);
  94. arrs2[9] = (arrs1[9]);
  95. arrs2[10] = (arrs1[10] + 10);
  96. // arrs2[10] = (arrs1[10] + 10); i would leave all like this if i wanted to display the int value in output
  97.  
  98.  
  99. pickednumber = arrs2[Math.floor(Math.random() * arrs2.length)];
  100.  
  101. if(pickednumber < minarrs || pickednumber > maxarrs ){
  102. console.log("Number is out of range");
  103. }
  104. else {
  105. console.log("The number is " + '' + pickednumber + 'and it is in range'); // Displays the number as integer and string
  106. }}
  107.  
  108. rangeofNumber() // runs the commands to see if the picked random number is in range between 1 to 10.
  109.  
  110.  
  111.  
  112.  
  113. // task 6
  114.  
Advertisement
Add Comment
Please, Sign In to add comment