JAVASCRIPT
a. Write the code to display all the elements of the array with a delimiter *
b. Write a script to add all the elements of the array and display the result.
c. Display an array of 5 elements entered by the user in sorted order.
d. Accept an array of 5 elements and print the array elements in the odd positions.
PLEASE ANSWER I HAVE 3 HOURS LEFT , OTHER WISE DUE TO THIS ASSUGNMENT I WILL BE EXPELLEX
Answers
Answer:
A. Print array with * as delimeter
var fruits = ["Banana", "Orange", "Apple", "Mango"];
var fLen = fruits.length;
var text = "";
for (i = 0; i < fLen; i++) {
text += fruits[i] + "*";
}
Console.log(text);
B. Add all elements of an array and display result
var arr = [10, 20, 30, 40];
var arrLen = arr.length;
var sum = 0;
for (i = 0; i < arrLen; i++) {
sum += arr[i];
}
Console.log(sum);
C. Display an array of 5 elements entered by the user in sorted order.
var arr = [10, 20, 30, 40];
var arrLen = arr.length;
arr.sort();
for (i = 0; i < arrLen; i++) {
Console.log(arr[i]);
}
D. Accept an array of 5 elements and print the array elements in the odd positions.
var nums = [1, 2, 3, 4, 5, 6, 7, 8, 9];
var arrLen = arr.length;
arr.sort();
for (i = 0; i < arrLen; i++) {
if ((nums[i] % 2) != 1) {//console.log(nums[i]); }
else { console.log(nums[i] ); }
}
Answer:
bro ...apeejay?
Explanation: