Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

216
Views
property value assign to variable (variable assign to function) return undefined

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"))

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!