Question: Develop an array of 1000 objects (having properties name and number as shown).
- We need a function to convert every object so the name is uppercased and values are 5 times the original and store into the higher variable. Similarly, another function that converts every object so the name is lower case and value is 3 times the original, store this into the little variable.
- We need a function that takes each object in higher and finds all objects in little that evenly divide into it. Example: 30 in higher object is evenly divided by 6 in little.
- The output of 2 must be an array of higher numbers, and in every
object there should be
got(which is a variable inside the object) which will contain every little object that evenly divided the higher.
My code:
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<script>
var n = 1000;
var sample = [];
for (var i = 0; i < n; i++) sample.push({
name:'John' + i,
value: i
});
console.log(sample);
function Converter() {
var n = 1000;
var higher = sample;
for (var i = 0; i < n; i++) higher.name = 'John' + i;
higher.value = i * 5;
console.log(higher);
}
</script>
</body>
</html>
The array of objects is created and it is as expected/required by the question, however, the converter function for higher does not work, also how should the 3rd question be done?
sampleis the array, not an item inside the array. When you accesshigher.nameandhigher.valueyou are accessing an undefined property in the array. Also, your syntax is not correct,forhas missing braces and you probably didn't intend to do that.