0% found this document useful (0 votes)
68 views1 page

JS Tema

The document provides an example of a function that takes an array of integers as a parameter and returns the number of even and odd values. It explains to use two variables (e.g. odd_values, even_values) to store the output and iterate through the array using a for loop, checking if each value is even or odd using the modulo operator and incrementing the corresponding variable. A sample output for the array [1,4,7,11,12] would be: Odd values: 3, Even values: 2.

Uploaded by

Tóth Szabolcs
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
68 views1 page

JS Tema

The document provides an example of a function that takes an array of integers as a parameter and returns the number of even and odd values. It explains to use two variables (e.g. odd_values, even_values) to store the output and iterate through the array using a for loop, checking if each value is even or odd using the modulo operator and incrementing the corresponding variable. A sample output for the array [1,4,7,11,12] would be: Odd values: 3, Even values: 2.

Uploaded by

Tóth Szabolcs
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

.

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

Example: for array [1,4,7,11,12] the returned result will be:

Odd values: 3

Even values: 2

Hint: Use the example that we did in the class, with calculating the maximum number
from a given array. Use two variables for storing the output results (e.g.
odd_values, even_values)

<script>
function tema(sir){
var even = 0;
var odd = 0;

for(var i = 0; i < sir.length; i++){


if ( sir[i] % 2 === 0){
even++
}
else
odd++

}
document.write("Total even numbers:" + even, "; ", "Total odd numbers:" + odd);
}
document.write(tema([1,2,3,10,11,12,13,14,16]));

</script>

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.

E.g. calling the function for strings: "happy" and "testing" will return "HAPPY
TESTING"

<script>
function tema2(a, b){
var c = a + " " + b;

return c.toUpperCase()
}
document.write(tema2("happy", "testing"));
</script>

You might also like