Guest User

Untitled

a guest
Jul 15th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.38 KB | None | 0 0
  1. // Check Whether Even or Odd
  2.  
  3. function fun1(n){
  4. if (Number.isInteger(n)){
  5. if (n==0){
  6. console.log("Zero is neither Even nor Odd")}
  7. else if(n%2==0){
  8. console.log("GIven number is Even")
  9. }
  10. else
  11. console.log("Given number is Odd")
  12. }
  13. else
  14. console.log("Input is not a valid Number")
  15. }
  16.  
  17.  
  18.  
  19. // Generate Even and Odd Number less than N and Generate β€˜N’Even and Odd Numbers
  20.  
  21. var Even=[];
  22. var Odd=[];
  23. var allEven=[];
  24. var allOdd=[];
  25.  
  26. function OrN(n){
  27. if(Number.isInteger(n)){
  28. if(n==0){
  29. console.log("Zero is Even nor Odd")
  30. }
  31. else if (n%2==0){
  32. for (i=n;i>=2;i=(i-2)){
  33. Even.push(i-2);
  34. Odd.push(i-1);
  35. }
  36.  
  37. }
  38. else{
  39. for (i=n;i>=2;i=(i-2)){
  40. Even.push(i-1);
  41. Odd.push(i-2);
  42. }
  43. }
  44.  
  45. for (x=0;x<(2*n);x=(x+2)){
  46. allEven.push(x+2);
  47. allOdd.push(x+1);
  48. }
  49.  
  50. }
  51. else{
  52. console.log("Invalid Input")
  53. }
  54. console.log(Odd);
  55. if (n%2==0)
  56. console.log(Even.slice(0,Even.length-1));
  57. else
  58. console.log(Even);
  59. console.log(allOdd);
  60. console.log(allEven);
  61. }
  62.  
  63. //to decide given N is Prime or not
  64.  
  65. function isPrime(n) {
  66. if(num < 2) return false;
  67. var prime = n != 1;
  68. for(var i=2; i<num; i++) {
  69. if(n % i == 0) {
  70. prime = false;
  71. break;
  72. }
  73. }
  74. return prime;
  75. }
  76.  
  77. // prints the numbers from 1 to 100 and for multiples of '3' print"Fizz" instead of the number and
  78. for the multiples of '5' print "Buzz".
  79.  
  80.  
  81. function ran(){
  82.  
  83. for(i=1;i<=100;i++){
  84.  
  85. if(i%3==0){
  86. console.log("Fizz")
  87. }
  88. else if(i%5==0){
  89. console.log("Buzz")
  90. }
  91. else
  92. console.log(i)
  93.  
  94. }
  95. }
  96.  
  97. //Sum of Array Elements
  98.  
  99. function sumArray(array) {
  100. for (let index = 0,length = array.length,sum = 0; index < length;sum += array[index++]);
  101. return sum;
  102. }
  103. //check whether given character is vowel or consonant
  104.  
  105. let vowels=[a,e,i,o,u];
  106. let consonants=[b,c,d,f,g,h,j,k,l,m,n,p,q,r,s,t,v,w,x,y,z];
  107.  
  108. function VoC(){
  109.  
  110. for (int i = 0; i < vowels.length-1; i++) {
  111. for (int k = i + 1; k < vowels.length-1; k++) {
  112.  
  113. if(vowels[i]=vowels[k]){
  114. console.log("vowel");
  115. }
  116. else
  117. console.log("Consonent")
  118. }
  119. }
  120. }
  121.  
  122. // the largest number among three numbers
  123. function bigAmong(a,b,c){
  124.  
  125. if (a>b){
  126.  
  127. if(a>c){
  128. console.log("A is greatest");
  129. }
  130. else
  131. console.log("C is the greatest");
  132. }
  133. else if (b>c){
  134. console.log("B is greatest");
  135. }
  136. else
  137. console.log("C is greatest");
  138. }
Add Comment
Please, Sign In to add comment