Javascript Basic Coding Introduction Practice assignments

  1. Working with Linear Data Structures Arrays
    1. write a script to print all array values in the console.
    2. For the Given array: [23,34,54,0,4,7] print all the Array values using a for loop. Expected output: 23 34 54 0 4 7
    3. print all numbers in an array except the first element. Expected output: 34 54 0 4 7
    4. Print all elements in an array except the last element Expected output: 23 34 54 0 4
    5. Print all the numbers from last index to first index Expected output: 7 4 0 54 34 23
    6. Print all the numbers from last index to first index except the first element Expected output: 4 0 54 34 23
    7. Print all the numbers from last index to first index except the last element Expected output: 7 4 0 54 34
    8. Print only the last 4 elements of an array. Expected output: 54 0 4 7
    9. For the Given array: [23,34,54,10,4,7] print the minimum number in an Array. Expected output: 4
    10. For the Given array: [23,34,54,10,4,7] print the Maximum number in an array. Expected output: 54
    11. For the Given array: [23,34,54,10,4,7] sum of all the numbers in an Array. Expected output: 132
    12. For the Given array: [23,34,54,10,4,7] Average of all the numbers in an Array. Expected output: 22
    13. For the Given array: [23,34,54,10,4,7] print values that are greater than the given number. Given number: 20, Expected output: 23,34,54
    14. For the Given array: [23,34,54,10,4,7] print all the even numbers in an Array. Expected output: 34,54,10,4
    15. For the Given array: [23,34,54,10,4,7] print all the odd numbers in an Array. Expected output: 23,7
    16. For the Given array: [23,-34,-54,10,-4,7] print all the positive numbers in an array. Expected output: 23,10,7
    17. For the Given array: [23,34,54,10,4,7] search if the given number is there in an array or not. Given number: 34, Expected output: true Given number: 26, Expected output: false
    18. For the Given array: [23,34,54,10,34,7,23,10,34] print the total number of times an element found in the array. Given number: 23, Expected output: 2 Given number: 34, Expected output: 3 Given number: 10, Expected output: 2 Given number: 54, Expected output: 1
    19. For the Given array: [23,34,54,10,4,7] print index of a given element in an Array. Given number: 23, Expected output: 0 Given number: 34, Expected output: 1 Given number: 10, Expected output: 3 Given number: 54, Expected output: 2
    20. For the Given array: [23,34,54,10,34,7,23,10,34] eliminate duplicates in a given array Expected output: 23,34,54,10,7
    21. a program to store an array into another array var ar = [23,34,54,10,4,7] var br = [ ] Expected output: br = [23,34,54,10,4,7]
    22. Sort an array in ascending order. Given array: [23,34,54,10,4,7] Expected output: 4,7,10,23,34,54
    23. Reduce the each element of the array by 25% and store in a separate array.
    24. Store only even numbers of a given array in another array.
    25. create a duplicate array for a given array.
    26. Eliminate duplicates from a array
    27. print only the perfect squares in an array
    28. Print only the 2 digit numbers from an array
    29. Print only multiples of 5 from an array
    30. Print only multiples of 2 AND 3 from an array
    31. Print only multiples of 3 OR 5 from an array
    32. Increment 5% for all the salaries in a given array
    33. For every basic salary present in the array, add 40% HRA, 92% DA, 10% Tax and display the final output
    34. For every salary, deduct 10% tax for salaries less than 50000 and deduct 12% tax for salaries more than 50000
    35. Print only those odd numbers in a given array which are divisible by 3.
    36. Insert first 10 odd numbers in an empty array(for and while).
    37. Print the elements present in the second half of the array.
    38. Print the greatest of all 2-digit numbers present in an array.
    39. Write a program to remove elements from an array which are not in the ascending order Ex: Original array: [12,34,11,56,37,98,23,67,109,45] Output : [12,34,56,98,109]
    40. Write a program to sort the array based on the number of occurrences of elements Ex: original array: [1,2,5,6,2,1,6,1,2,6,2,1,2]; After the logic: [5,6,6,6,1,1,1,1,2,2,2,2,2]; //5 occurred one time,6 three times,1 occurred 4 times, 2 occurred 5 times
    41.                             var ar = [19,12,23,4,15];
                                  var br = [26,37,18,79,10];
                                  a)Write script to merge array as the values of ar in the first and values of br next
                                      Expected output: [19,12,23,4,15,26,37,18,79,10];
                                  b)Write script to merge array as the values of ar in the first and values of br next
                                      Expected output: [26,37,18,79,10,19,12,23,4,15];
                              
    42.                             var ar = [1,2,3,7,8,9];
                                  var br = [4,5,6];
                                  Expected output: [1,2,3,4,5,6,7,8,9];
                              
    43. insert An Element Desired or Specific Position In An Array
    44. Remove Duplicates Items In An Array
    45. Delete Element From Array At Desired Or Specific Position
    46. Check String Is Palindrome Or Not Using For Loop
    47. Convert All Input String Simultaneously Into Asterisk ( * )
    48. Read and print elements of the array. – using recursion.
    49. Print all negative elements in an array.
    50. Sum of all array elements. – using recursion.
    51. Find a maximum and minimum element in an array. – using recursion.
    52. Get the second largest element in an array.
    53. Count the total number of even and odd elements in an array.
    54. Count the total number of negative elements in an array.
    55. Copy all elements from an array to another array.
    56. Insert an element in an array.
    57. Delete an element from an array at the specified position.
    58. Count frequency of each element in an array.
    59. Print all unique elements in the array.
    60. Count the total number of duplicate elements in an array.
    61. Delete all duplicate elements from an array.
    62. Merge two arrays to the third array.
    63. Find the reverse of an array.
    64. Put even and odd elements of an array in two separate arrays.
    65. Search an element in an array.
    66. Sort array elements in ascending or descending order.
    67. Sort even and odd elements of the array separately.
    68. Right rotate an array.
    69. Working with Object Literals
    70. Given an object:
                                  var person = {
                                      "firstName" : "Harry",
                                      "lastName" : "Potter",
                                      "age": 30,
                                      "gender": "male",
                                      "skill" : "ReactJS",
                                      "expertise": "Beginner"
                                  };
                              
      1. Print the firstname.
      2. Print the lastname.
      3. Print the fullname("Harry Potter").
      4. If the age is less than 18, then print "false". If the age is more than 18, then print "true".
    71. For the given marks object solve the following
                                  var marks = {
                                      "maths" : 34,
                                      "english" : 56,
                                      "science": 32,
                                      "hindi" : 75,
                                      "social science": 65
                                  };
                              
      1. Print the marks of all the subjects.
      2. Print the names of all the subjects from the given object.
      3. Count the number of subjects from the given object.
      4. Print the percentage of the marks of the student.
      5. Print only those subjects where the student scored more than 35.
      6. Print the pass/fail status of the subjects provided 35 is the pass mark.
      7. Print only the passed subjects.
      8. Count the number of passed subjects.
      9. Print only the failed subjects.
      10. Count the number of failed subjects.
      11. Print the least scored subject.
      12. Print the highest scored subject.
      13. Check whether the student has passed in all the subjects or not.
      14. Take the subject name from the student through prompt box and print the subject marks and pass/fail status.
    72. For the given Object Solve the following
                                  var products = [
                                  {
                                      "name": "Duracell - AAA Batteries (4-Pack)",
                                      "type": "HardGood",
                                      "price": 5.49,
                                      "category": "Household Batteries",
                                      "manufacturer": "Duracell",				
                                  },
                                  {
                                      "name": "Hard Rock TrackPak - Mac",
                                      "type": "Software",
                                      "price": 29.99,
                                      "category": "Recording Equipment",
                                      "manufacturer": "Hal Leonard",				
                                  },
                                  {
                                      "name": "Duracell - AA 1.5V CopperTop Batteries (4-Pack)",
                                      "type": "HardGood",
                                      "price": 5.62,
                                      "category": "Household Batteries",
                                      "manufacturer": "Duracell",				
                                  },
                                  {
                                      "name": "Energizer - MAX Batteries AA (4-Pack)",
                                      "type": "HardGood",
                                      "price": 5.32,
                                      "category": "Household Batteries",
                                      "manufacturer": "Energizer",				
                                  },
                                  {
                                      "name": "METRA - Antenna Cable Adapter - Black",
                                      "type": "HardGood",
                                      "price": 13.99,
                                      "category": "Antennas & Adapters",
                                      "manufacturer": "Metra",				
                                  },
                                  {
                                      "name": "WipeDrive Six - Mac|Windows",
                                      "type": "Software",
                                      "price": 23.99,
                                      "category": "Maintenance Software",
                                      "manufacturer": "White Canyon",				
                                  }
                              ];
                              
      1. Print all the product names.
      2. Print all the hardgoods.
      3. Print all the softwares.
      4. Print all the categories.
      5. Print only the products manufactured by Duracell.
      6. Print the product names in ascending order of their prices.
      7. Print only those products whose price is more than 14.99.
      8. Print only those products whose price is less than 9.99.
      9. Print the total price of all the hardgoods.
      10. Print the average price of the softwares.
    73.                             var people = [
                                  {
                                  "firstname": "praveen",
                                  "lastname": "gubbala",
                                  "age": 36,
                                  "gender": "male",
                                  "city": "hyd",
                                  "salary": 10000
                                  },
                                  {
                                  "firstname": "srikanth",
                                  "lastname": "gubbala",
                                  "age": 32,
                                  "gender": "male",
                                  "city": "bengaluru",
                                  "salary": 20000
                                  },
                                  {
                                  "firstname": "pradeep",
                                  "lastname": "reddy",
                                  "age": 21,
                                  "gender": "male",
                                  "city": "hyd",
                                  "salary": 30000
                                  },
                                  {
                                  "firstname": "mounika",
                                  "lastname": "mudiraj",
                                  "age": 20,
                                  "gender": "female",
                                  "city": "nalgonda",
                                  "salary": 30000
                                  },
                                  {
                                  "firstname": "nikhil",
                                  "lastname": "m",
                                  "age": 22,
                                  "gender": "male",
                                  "city": "guntur",
                                  "salary": 2000
                                  },
                                  {
                                  "firstname": "riya",
                                  "lastname": "bhadouria",
                                  "age": 14,
                                  "gender": "female",
                                  "city": "indore",
                                  "salary": 40000
                                  }
                                  ];
      
      
                              
      1. Print all the firstnames.
      2. Print all the full names.
      3. Print only those names whose age is more than 25.
      4. Print all female names.
      5. Print only those names whose salary is more than 30000 and increase their salaries by 15%.
      6. Using prompt, print only those names whose city is "hyd".
      7. Print the total salary of all the people.
      8. Print all the female names.
      9. Print all the firstnames whose salary is more than 30000.
      10. Using prompt, print all names whose city is "hyd".
      11. Print all the fullnames in the alphabetical order.
      12. Print all the fullnames in the increasing order of their age.
      13. Print all the fullnames in the reverse alphabetical order.
      14. Print all the fullnames in the decreasing order of their salaries.
      15. Print all the cities in which the people live. There should not be any duplicate cities.
      16. Print all the male names whose age is greater than 25.
      17. Print all names that starts with "p" and the firstname should be in UPPERCASE. e.g. PRAVEEN gubbala.
    74. Working with Strings
    75. Find the first occurrence of a character in a given string.
    76. Find the last occurrence of a character in a given string.
    77. Search all occurrences of a character in a given string.
    78. Count occurrences of a character in a given string.
    79. Find the highest frequency character in a string.
    80. Find the lowest frequency character in a string.
    81. Count the frequency of each character in a string.
    82. Remove the first occurrence of a character from a string.
    83. Remove the last occurrence of a character from a string.
    84. Delete all occurrences of a character from a string.
    85. Remove all repeated characters from a given string.
    86. Replace the first occurrence of a character with another in a string.
    87. Replace the last occurrence of a character with another in a string.
    88. Put all occurrences of a character with another in a string.
    89. Find the first occurrence of a word in a given string.
    90. Find the last occurrence of a word in a given string.
    91. Search all occurrences of a word in a given string.
    92. Count occurrences of a word in a given string.
    93. Remove the first occurrence of a word from the string.
    94. Remove the last occurrence of a word in a given string.
    95. Delete all occurrence of a word in a given string.
    96. A Trim leading white space characters from a given string.
    97. Trim trailing white space characters from a given string.
    98. Trim both leading and trailing white space characters from a given string.
    99. Remove all extra blank spaces from the given string.
    100. A String is Palindrome or Not
    101. A String Is an Anagram or Not
    102. Find the length of a string.
    103. Copy one string to another string.
    104. Concatenate two strings.
    105. Compare two strings.
    106. Convert lowercase string to uppercase.
    107. Convert uppercase string to lowercase.
    108. Toggle case of each character of a string.
    109. Find a total number of alphabets, digits or special character in a string.
    110. Count the total number of vowels and consonants in a string.
    111. Count the total number of words in a string.
    112. Find the reverse of a string.
    113. Check whether a string is a palindrome or not.
    114. Reverse order of words in a given string.
    115. Reverse of a number using toString, split, reverse and join methods.
    116. Elimination of zeroes from a given number.
    117. Find the number of digits of a given number using toString() and length property
    118. Write a program to take a string and print only the numeric characters using. Example: Input->‘Q1STR5684AK’; Output->‘15684’
    119. Search for a given number in an array
    120. Print the number of words in a given string
    121. Remove the single spaces from a given sentence
    122. remove all the spaces from a given string
    123. Search a given string in a sentence(both uppercase and lowercase)
    124. Write a program to convert a sample sentence string into an array of all the words in the sentence. Example: Input->‘Hello World’; Output->[‘Hello’,‘World’]
    125. Write a program to eliminate all numeric characters from a string. Example: Input->‘Q1STR5684A’; Output-> ‘QSTRAK’
    126. Write a program to take a string and print only the numeric characters. Example: Input->‘Q1STR5684AK’; Output->‘15684’
    127. Write a program to take a string and print the number of characters in the string. Example: Input->‘Hello’; Output->5
    128. Write a program to take a 16-digit credit card number and replace the first 12 characters with ‘X’. Example:Input->‘9765143265387960’; Output->‘XXXXXXXXXXXX7960’
    129. Write a program to take a string and replace all vowels with ‘8’. Example: Input->‘This is awesome’; Output->‘Th8s 8s 8w8s8m8’
    130. Write a program to hide the middle six digits of a phone number. Example: Input-> '9876543210'; Output-> '98XXXXXX10'
    131. Append the calling code of India(+91) to a given phone number. Example: Input-> '9876543210'; Output-> '+919876543210'
    132. Check whether a given number is a valid phone number.
              Example:Input-> '7654893274'; Output-> 'valid'
              Input-> '785487438754'; Output-> 'invalid'.........(must be 10 digits)
              Input-> '7854s54839'; Output-> 'invalid'.............(must NOT contain letters)
          
    133. Check whether a given number is a valid credit card number. Example:
              Example:
              Input-> '7463836483647454'; Output-> 'valid'
              Input-> '74638364836474548'; Output-> 'invalid'...(must be 16 digits)
              Input-> '7463836w4836o745'; Output-> 'invalid'...(must contain only numbers)
          
    134. Write a program to add hyphens (-) in between a given credit card number.
              Example:
              Input-> '6484638463487486'; Output-> '6484-6384-6348-7486'
                              
    135. Sort a given string
              Example: ‘praveen’=>’aeenprv’
                              
    136. Eliminate Duplicate characters in given string
              Example: ‘praveengubbala’ => ‘pravengubl’
                              
    137. Write a program to print only numbers out of a given string
              Example: let us take pr34s2v9q4
              The output should be 3,4,2,9,4