Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript

Christian 123
Christian 123
6,899 Points

A mistake? But better :D

I got confused and thought he mean to make different students with different properties so yea i did this xD i could have done what he actualy wanted way easier, check it

var students = [
];

function randomNumber(lowNum, highNum) {
    var answer = Math.floor(Math.random() * (highNum - lowNum + 1) + lowNum );
    return answer;
}

function randomTrack() {
    var track = Math.floor(Math.random() * (3 - 1 + 1) + 1 );
    if (track === 3) {
        track = 'Front-End development';
    } else if (track === 2) {
        track = 'Back-End development';
    } else {
        track = 'Graphic Designer';
    }
    return track;
}

function nameRandom(howMany) {

    var whatName = Math.floor(Math.random() * (howMany - 1 + 1) + 1);
    var nameArray = ['Corliss',  'Salina',  'Melissia', 'Shona',  'Edda',  'Taryn',  'Rosalina', 'Honey',  'Francine',  'Robyn'];
    whatName = nameArray[whatName];
    return whatName;
}

for (i = 0; i < randomNumber(5, 10); i++) {
    students.push(
        {
        name: nameRandom(randomNumber(1, 10)),
        track: randomTrack(),
        achievements: randomNumber(0, 10),
        points: randomNumber(0, 50) + '<br>'
        }
    )
}
var holder = '';
for (i = 0; i < students.length; i++) {
for (key in students[i]) {
      document.write('<b>', key, ': ', students[i][key], '</b>', '<br>');
    }
}

Try it out in workshop or whatever text editor you're using and keep refreshing

1 Answer

Steven Parker
Steven Parker
220,450 Points

Have fun while you're learning, but remember...

The ability to create a program in the least amount of time that produces the result they want is a skill most admired by employers. :star2:

The ability to spend more time to create something that produces a result different than what they want will generally not be well appreciated. :stuck_out_tongue_closed_eyes:

Christian 123
Christian 123
6,899 Points

Yea of course, i just generally didn't understand what he said so i did it my own way :P