diff --git a/students/devendra-katwal/averageGrade.js b/students/devendra-katwal/averageGrade.js new file mode 100644 index 0000000..96daab3 --- /dev/null +++ b/students/devendra-katwal/averageGrade.js @@ -0,0 +1,34 @@ +// 6. Write a JavaScript program which compute, the average marks of the following students Then, +// this average is used to determine the corresponding grade. + +// Student Name Marks +// David 80 +// Vinoth 77 +// Divya 88 +// Ishitha 95 +// Thomas 68 + +// The grades are computed as follows: +// Range Grade +// <60 F +// <70 D +// <80 C +// <90 B +// <100 A' + +let marks = { + +'David':80, +'Vinoth':77, +'Divya':88, +'Ishitha' :95, +'Thomas' :68, +} +function gradeCalculator(input){ +let num = [] +for(item in input){ + num.push(input[item]); +} +return num +} +console.log(gradeCalculator(marks)); \ No newline at end of file diff --git a/students/devendra-katwal/display-larger.js b/students/devendra-katwal/display-larger.js new file mode 100644 index 0000000..fd7683e --- /dev/null +++ b/students/devendra-katwal/display-larger.js @@ -0,0 +1,10 @@ +// 1. Write a JavaScript program that accept two integers and display the larger. +function displayLarger(arg1,arg2){ + if(arg1 >arg2){ + return arg1 + }else{ + return arg2 + } +} + +console.log(displayLarger(4,2)); \ No newline at end of file diff --git a/students/devendra-katwal/ex1-sample.js b/students/devendra-katwal/ex1-sample.js new file mode 100644 index 0000000..e69de29 diff --git a/students/devendra-katwal/findSign.js b/students/devendra-katwal/findSign.js new file mode 100644 index 0000000..53ac390 --- /dev/null +++ b/students/devendra-katwal/findSign.js @@ -0,0 +1,13 @@ +// 2. Write a JavaScript conditional statement to find the sign of product of three numbers. +// Display an alert box with the specified sign. + +function findSign(a,b,s){ + let product = a*b*s; + if (product < 0){ + return '-' + }else{ + return '+' + } +} + +console.log(findSign(1,-2,-4)); diff --git a/students/devendra-katwal/largest.js b/students/devendra-katwal/largest.js new file mode 100644 index 0000000..919dc3e --- /dev/null +++ b/students/devendra-katwal/largest.js @@ -0,0 +1,11 @@ +// 4. Write a JavaScript conditional statement to find the largest of five numbers. Display an alert box to show the result. +// Sample numbers : -5, -2, -6, 0, -1 +// Output : 0 +let a = [-5, -2, -6, 0, -1 ] +function largest(input){ + let big = input.sort((a,b)=>b-a); + return big[0]; +} +let b = largest(a); +console.log(b); +console.log(largest([-5,-2,-9])); \ No newline at end of file diff --git a/students/devendra-katwal/oddEven.js b/students/devendra-katwal/oddEven.js new file mode 100644 index 0000000..b31f4cb --- /dev/null +++ b/students/devendra-katwal/oddEven.js @@ -0,0 +1,22 @@ +// 5. Write a JavaScript for loop that will iterate from 0 to 15. For each iteration, it will check if the current number is odd or even, and display a message to the screen. +// Sample Output : +// "0 is even" +// "1 is odd" +// "2 is even" +// ---------- +// ---------- + +function oddEven(){ + var result = {}; + for(let i = 0; i<=15; i++){ + if(i%2 === 0 ){ + result[i] = 'even'; + }else if ( i === 0){ + result[i] = 'zero'; + }else{ + result[i] = 'odd'; + } + } + return result; +} +console.log(oddEven()); \ No newline at end of file diff --git a/students/devendra-katwal/questions.txt b/students/devendra-katwal/questions.txt new file mode 100644 index 0000000..1152e6c --- /dev/null +++ b/students/devendra-katwal/questions.txt @@ -0,0 +1,51 @@ +1. Write a JavaScript program that accept two integers and display the larger. +2. Write a JavaScript conditional statement to find the sign of product of three numbers. Display an alert box with the specified sign. +Sample numbers : 3, -7, 2 +Output : The sign is - +3. Write a JavaScript conditional statement to sort three numbers. Display an alert box to show the result. +Sample numbers : 0, -1, 4 +Output : 4, 0, -1 +4. Write a JavaScript conditional statement to find the largest of five numbers. Display an alert box to show the result. +Sample numbers : -5, -2, -6, 0, -1 +Output : 0 +5. Write a JavaScript for loop that will iterate from 0 to 15. For each iteration, it will check if the current number is odd or even, and display a message to the screen. +Sample Output : +"0 is even" +"1 is odd" +"2 is even" +---------- +---------- +6. Write a JavaScript program which compute, the average marks of the following students Then, +this average is used to determine the corresponding grade. + +Student Name Marks +David 80 +Vinoth 77 +Divya 88 +Ishitha 95 +Thomas 68 + +The grades are computed as follows: +Range Grade +<60 F +<70 D +<80 C +<90 B +<100 A + +7. Write a JavaScript program which iterates the integers from 1 to 100. But for multiples of three print "Fizz" instead of the number and for the multiples of five print "Buzz". For numbers which are multiples of both three and five print "FizzBuzz". +8. According to Wikipedia a happy number is defined by the following process: +"Starting with any positive integer, replace the number by the sum of the squares of its digits, and repeat the process until the number equals 1 (where it will stay), or it loops endlessly in a cycle which does not include 1. Those numbers for which this process ends in 1 are happy numbers, while those that do not end in 1 are unhappy numbers (or sad numbers)". +Write a JavaScript program to find and print the first 5 happy numbers. +9. Write a JavaScript program to find the armstrong numbers of 3 digits. +Note: An Armstrong number of three digits is an integer such that the sum of the cubes of its digits is equal to the number itself. For example, 371 is an Armstrong number since 3**3 + 7**3 + 1**3 = 371. +10. Write a JavaScript program to construct the following pattern, using a nested for loop. +* +* * +* * * +* * * * +* * * * * +11. Write a JavaScript program to compute the greatest common divisor (GCD) of two positive integers. +12. Write a JavaScript program to sum the multiples of 3 and 5 under 1000. + + diff --git a/students/devendra-katwal/sort.js b/students/devendra-katwal/sort.js new file mode 100644 index 0000000..13471c7 --- /dev/null +++ b/students/devendra-katwal/sort.js @@ -0,0 +1,15 @@ +// 3. Write a JavaScript conditional statement to sort three numbers. +// Display an alert box to show the result. +// Sample numbers : 0, -1, 4 +// Output : 4, 0, -1 + + +function sortItems(input){ + return input.sort(function(a,b){ + return b-a + }) +} + + + +console.log(sortItems([1,4,3])); \ No newline at end of file