Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

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
230,274 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