in this excercise, i create 2 variable assign to 2 function. getrandomMark function will return a random number. in generateStudentMark function, i create an object student with name and marks property; marks is an object with property is subject name and value is a random number from getrandomMark function. but property value can return undefined as in this image score() return undefinedand im not sure why
var score = function getRandomMark(start, end, step) {
var num = start
var arr = []
arr.push(num)
while (num <= (end - step)) {
num += step
arr.push(num)
}
// random range [0 - arr.length - 1]
var index = Math.floor(Math.random() * (arr.length + 1))
return arr[index]
}
// bai2
// assign var len
var generateMark = function generateStudentMark(name) {
var student = {
"name": name,
"marks": {
"literature": score(0, 10
, 0.5),
"maths": score(0, 10
, 0.5),
"chemistry": score(0, 10
, 0.5),
"history": score(0, 10
, 0.5),
"biology": score(0, 10
, 0.5)
}
}
return student
}
console.log(generateMark("Chi"))