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 trialReza Sorasti
491 PointsA question on the this Java script code
Below is the code in the index.html file:
code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Students</title>
<link rel="stylesheet" href="css/styles.css">
</head>
<body>
<h1>Students</h1>
<div id="output">
</div>
<script src="js/students.js"></script>
<script src="js/student_report.js"></script>
</body>
</html>
Now Below is the Javascript code in the student.js file:
code
var students = [
{
name: 'Dave',
track: 'Front End Development',
achievements: '158',
points: '14730'
},
{
name: 'Jody',
track: 'iOS Development with Swift',
achievements: '175',
points: '16375'
},
{
name: 'Jordan',
track: 'PHP Development',
achievements: '55',
points: '2025'
},
{
name: 'John',
track: 'Learn WordPress',
achievements: '40',
points: '1950'
},
{
name: 'Trish',
track: 'Rails Development',
achievements: '5',
points: '350'
}
];
And below is the code in the student_report.js file:
code
var message = '';
var student;
var search;
function print(message) {
var outputDiv = document.getElementById('output');
outputDiv.innerHTML = message;
}
while(true) {
search = prompt('Please type in a student name or type in "quit" to end the program');
if ( search === null || search.tolowercase() === 'quit') {
break;
}
}
for (var i = 0; i < students.length; i += 1) {
//student = students[i];
message += '<h2>Student: ' + students[i].name + '</h2>';
message += '<p>Track: ' + students[i].track + '</p>';
message += '<p>Points: ' + students[i].points + '</p>';
message += '<p>Achievements: ' + students[i].achievements + '</p>';
}
print(message);
When I load the page, i get the prompt box that asks to type in a student name or quite. My question is why is that after I type in quit, and the prompt box goes away, the only text that is displayed in the browser's screen is the header Students. I was expecting to have the javascript program to go in the for loop and put all the object property values in the Student array and put them in the message variable and as a result I would be able to see that student record list printed to the browser's screen. From my understand, when the user types in "quit" in the prompt box, the program using the break keyword, should get out of the while loop and it should not end. The program should go to the next statement out side of the while loop and run the for loop and then run the print function. So, that is why I don't understand why I am not seeing that the student records in the brower's screen after I type in "quit". Any help is appreciated.
Reza Sorasti
491 PointsHow method do you use to attach codes in a well-formatted form? I just copy and past the code from my editor Atom to the posting editor and when I paste the code into the posting editor, all the formatting of the code gets screwed...
Steven Parker
231,248 PointsUse the instructions for code formatting in the Markdown Cheatsheet pop-up below the "Add an Answer" area.
Or watch this video on code formatting.
2 Answers
Steven Parker
231,248 PointsSince JavaScript is case-sensitive, it's important to spell the name of the "toLowerCase" function with a capital "L" and a capital "C".
That will at least get it working. Then you have a little code to write yet to limit the output to just the students asked for.
Reza Sorasti
491 PointsThe issue is resolved. I need use toLowerCase instead of tolowercase
James Reinhold
12,361 PointsJames Reinhold
12,361 PointsI am trying to figure this out but your question and code it's not well laid out. Reference here: https://teamtreehouse.com/community/cheatsheet to attach codes in a well-formatted form and to be able to get the appropriate help I will advise you keep the question simple