Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Exercise A
- // Task 1. two int. which is largest
- let num1 = 1;
- let num2 = 2;
- let num3 = 3;
- let largest = Math.max(num1, num2, num3);
- console.log("The largest number is " + largest);
- //Task 2. two int, check if they divide each other
- function divtest(variable1, variable2) {
- variable1 = prompt("Enter a Value to check if divisible");
- variable2 = prompt("Enter a Value to check if divisible");
- varin1 = parseInt(variable1);
- varin2 = parseInt(variable2);
- if (varin1 % varin2 === 0) {
- console.log("Number 1 is divisible by number 2 ");
- } else if (varin2 % varin1 === 0) {
- console.log("Number 2 is divisible by number 1");
- } else {
- console.log("No Number can Divise the other/improper input");
- }
- }
- // this runs the function .. you can input any number and try!
- divtest();
- //Task 3. Two int, show the larger then smaller number
- function checkLarger(Numbers1, Numbers2) {
- Numbers1 = prompt("Enter the first of two Numbers to check who's bigger")
- Numbers2 = prompt("eEnter the second of two Numbers to check who's bigger")
- if (Numbers1 == Numbers2) {
- console.log("Error, Numbers are the same!");
- } else if (Numbers1 > Numbers2) {
- console.log("Number 1 is bigger!"); }
- else if (Numbers1 < Numbers2) {
- console.log("Number 2 is bigger!"); }
- else {
- console.log("this is not possible");
- }}
- checkLarger();
- // task 4. One Int, boolean true, false or zero according to its value.
- // הלכתי על מספר רנדומלי
- // originalNumber = Math.random() === 0 ? -1 : 1;
- function checkValuenumber(originalNumber) {
- originalNumber = Math.floor(Math.random() * 3) - 1 ; // this will get a number between 1 and 3 including zero;
- originalNumber *= Math.round(Math.random()) ? 1 : -1; // this adds negative, including zero.
- Math.sign(originalNumber);
- console.log(originalNumber);
- if (Math.sign(originalNumber) === 1){
- console.log("True, I'm positive");
- } else if (Math.sign(originalNumber) === -1) {
- console.log("False, I'm negative");
- } else if (Math.sign(originalNumber) === 0 ){
- console.log("I must be Zero");
- }else {
- console.log("I must not be a number");
- }
- }
- checkValuenumber();
- // Task 5 Int from 1 to 10, show its name and if its out of range show error
- function rangeofNumber() {
- arrs1 = [' ','one ','two ','three ','four ',
- 'five ','six ','seven ','eight ','nine ','ten '];
- arrs2 = [1,2,3,4, 5, 6, 7, 8, 9, 10];
- minarrs = arrs2[1];
- maxarrs = arrs2[10];
- arrs2[1] = (arrs1[1]);
- arrs2[2] = (arrs1[2]);
- arrs2[3] = (arrs1[3]);
- arrs2[4] = (arrs1[4]);
- arrs2[5] = (arrs1[5]);
- arrs2[6] = (arrs1[6]);
- arrs2[7] = (arrs1[7]);
- arrs2[8] = (arrs1[8]);
- arrs2[9] = (arrs1[9]);
- arrs2[10] = (arrs1[10] + 10);
- // arrs2[10] = (arrs1[10] + 10); i would leave all like this if i wanted to display the int value in output
- pickednumber = arrs2[Math.floor(Math.random() * arrs2.length)];
- if(pickednumber < minarrs || pickednumber > maxarrs ){
- console.log("Number is out of range");
- }
- else {
- console.log("The number is " + '' + pickednumber + 'and it is in range'); // Displays the number as integer and string
- }}
- rangeofNumber() // runs the commands to see if the picked random number is in range between 1 to 10.
- // task 6
Advertisement
Add Comment
Please, Sign In to add comment