0% found this document useful (0 votes)
68 views

Javascript Exercise

The document contains two Javascript coding exercises. The first asks to write code to count the odd and even numbers in an array by assigning them to separate arrays based on their modulus. The code provided uses a forEach loop to assign each value to the 'odd' or 'even' key in an object based on its modulus. The second asks to write a function to concatenate two strings with a space between and convert to uppercase. The code provided uses the join and toUpperCase string methods to concatenate the array elements with a space and convert to uppercase.

Uploaded by

Ionescu
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
68 views

Javascript Exercise

The document contains two Javascript coding exercises. The first asks to write code to count the odd and even numbers in an array by assigning them to separate arrays based on their modulus. The code provided uses a forEach loop to assign each value to the 'odd' or 'even' key in an object based on its modulus. The second asks to write a function to concatenate two strings with a space between and convert to uppercase. The code provided uses the join and toUpperCase string methods to concatenate the array elements with a space and convert to uppercase.

Uploaded by

Ionescu
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

Javascript Homework

1. Given an array of integer numbers, compute how many values from the
array are odd and how many of them are even.

var mac = {even:[], odd:[]};


[1, 3, 5, 6, 8, 9].forEach(function(val,key,arr)
{
var pac = (val % 2) ? 'odd' : 'even';
mac[pac][mac[pac].length] = val;
});
console.log(mac);

2. Write a function that will take two strings as parameters and will return their
concatenation, with a space between it, all in upper case. 

var newStr = ["Am", "terminat"].join(" ");


console.log(newStr.toUpperCase());

You might also like