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 trialbrendon hanson
6,191 PointsI need help with this program!
First off the purpose of this is to have two clients at a bank with a separate record each. To access their record you must type in a certain code and then type in their name and the type quit to exit loop and see your file. Also I the "bank owner" so to speak should be able to add or subtract money from each persons account individually. Also whenever a certain goal is reached that person should receive an alert when looking at their account. Some of these things don't work. If you could help me fix this I would be so grateful! when prompted a code type 14 and when prompted name type luke or julie
var students = [
{
name: 'luke',
memberSince: 'October 9, 2017',
memberShip: 'Platinum',
OuncesofSilver: 4,
savings: 0,
checking: 1.60,
debts: 0,
booksDue: 0,
points: 50
},
{ name: 'julie',
memberSince: 'October 9, 2017',
memberShip: 'Gold',
OuncesofSilver: 0,
savings: 0,
checking: 0,
debts: 0,
booksDue: 0,
points: 10
}
];
var message = '';
var student;
var question;
var security;
//Custom Function that replaces document.write with a better alternative
function print(message) {
var outputDiv = document.getElementById('output');
outputDiv.innerHTML = message;
}
// These are the reports
function getReport( student ) {
var report = '<h2> Client: ' + student.name + '</h2>';
report += '<p> MemberShip: ' + student.memberShip + '</p>';
report += '<p> MemberSince: ' + student.memberSince + '</p>';
report += '<p> Points: ' + student.points + '</p>';
report += '<p> Checking: ' + student.checking + '</p>';
report += '<p> Debts: ' + student.debts + '</p>';
report += '<p> Savings: ' + student.savings + '</p>';
report += '<p> Ounces of Silver: ' + student.OuncesofSilver + '</p>';
return report;
}
// The security code to only allow the person with card to see his/her profile
while (true) {
security = prompt("Type in your card number to continue");
if ( parseInt(security) === 15873974569 || parseInt(security) === 21385997124 || parseInt(security) === 14) {
question = prompt("Would you like to see our records? Type in your name to see your record and type Quit to exit on the next prompt");
} else {
break;
}
if (question === null || question.toLowerCase() === 'quit') {
break;
}
for (var i = 0; i < students.length; i += 1) {
student = students[i];
if ( student.name === question.toLowerCase() ) {
message = getReport( student );
print(message);
}
}
}
if ( parseInt(student.points) > 250 ) {
alert(" 1 Month Free for any membership! OR wait for a bigger Reward!");
}
if ( parseInt(student.points) > 500 ) {
alert("50% of membership for 5 whole MONTHS! OR wait for better prize!");
}
if ( parseInt(student.points) > 1000 ) {
alert("Upgrade to next membership!");
}
if ( student.checking < 20 ) {
alert("Your checking account is low on cash! Get it to 20 dollars or you'll lose points soon!");
}
if ( student.debts > 0 ) {
alert("You owe money pay it off ASAP!");
}
if ( student.booksDue > 0 ) {
alert("You have book(s) due!");
}
if ( student.savings === 1 && student.OuncesofSilver === 0 ) {
alert("You need to save some money!");
}
print(message);
brendon hanson
6,191 PointsAlrighty, got it formatted and I have a description up top.
brendon hanson
6,191 PointsI did a few changes but still won't work. The thing is when i try to add to object it simply doesn't work...
1 Answer
Steven Parker
231,275 PointsMuch better looking! And good description of your intended function, but where you say "Some of these things don't work." you could still be more specific.
Also, for some of what you describe, there does not seem to be any code yet in the program to do the job. So it seems like you might just have a bit of work to do yet to finish the program.
General hint: it might be easier to store things like money and points as numbers instead of strings. This will also simplify the code you still need to write for adding and subtracting these amounts.
Steven Parker
231,275 PointsI'm not seeing the code were you "try to add to object". On which line numbers is that code?
brendon hanson
6,191 PointsIf you're wondering, this is how I tried to add to objects.
student.checking += 2;
student.checking = '3.6';
parseInt(student.checking) += 2;
sorry i didn't show it but thats what i did and a few other ways to no avail, this has been annoying
Steven Parker
231,275 PointsYour first example "student.checking += 2;
" should work. Where in the program did you add this?
brendon hanson
6,191 PointsI added it right after the array of objects. Keep in mind I had that on a separate file. I also tried it after the other aswell
Steven Parker
231,275 PointsI see. No, it would not work there because the value of "student" is not set until the search loop. And it's only a reference to the selected student inside the "if" statement that compares the name. The same thing would apply to the alerts at the end. They are responding to the last student in the array, not the one that was searched for.
brendon hanson
6,191 PointsSo what should I do then...I'm still confused....
brendon hanson
6,191 PointsDo I need to type the code somewhere else or change something
Steven Parker
231,275 PointsYour last revision has two separate blocks of code for the alerts, plus two separate sections for checking inside the loop. If you go back to assigning "student" in the loop, you could just have one section. And you could move the alerts into the loop so they are done only for the selected student (and eliminate the repeated code).
brendon hanson
6,191 PointsThanks, I have everything working now....this was a headache, but I'm glad it works! I learned a lot from this and thanks for your help!
Steven Parker
231,275 PointsSteven Parker
231,275 PointsWhen posting code, use the instructions for code formatting in the Markdown Cheatsheet pop-up below the "Add an Answer" area. Â Or watch this video on code formatting.
Even better for large or multi-part programs, you can make a snapshot of your workspace and post the link to it here.
And please describe what you need help with in more detail.