Join 105,763 Programmers for FREE! Ask your question and get quick answers from experts. There are 1,690 online right now! We've got more than 500 tutorials and 2,000 snippets. Join and find out why Dream.In.Code is the #1 programming help community on the internet! Registration is fast and FREE... Join Now!
I have managed to complete the problem from the first post but the project i am doing seems to get harder and more obscure the further i get. I have encountered a problem with creating functions and using them to convert values of an array when the array is written out.
function daysOverdue(dateDue) { if (dateDue = 300) { document.write('On shelf') } }
i have created the above code to write out the arrays, i have only included the array i am having trouble with in the code. What i need to do is covert dueArray[count] into text based on the value. i.e if the due date equals 300 then it writes out 'on shelf' instead. The code above is probably a mile off. i have tried lots of variations but this was my last attempt.
any hints, pointers or assistance would be fantastically appreciated. Thanks in advance
Okay, I think I got it working. YOu were having a lot of errors in the code. First off you forgot to place the bookArray in the code anywhere so it wasn't able to call to it in the functions. Then you also had the daysOverDue() functuion not returning anything (which is the rason it was always coming back undefined) additionally that was because you didn't have anything happen if the book was not "On Shelf". After that it was just the basics of trying to get all the variable names for the same thing to be spelt the same way. Here is the new (and mostly working)code:
I changed the code and made it work with dueArray instead of bookArray. It's returning 'undefined' because dateDue will never be 300. Take a closer look at your code.
} function daysOverdue(dateDue) { if (dateDue == 300) { return ('On shelf'); } else { return ("not on shelf"); } }
Hope that helped you out a little bit. Good luck.
Edit: I just saw what you wrote. Your first post does not contain the declaration for bookArray. It contains references to it, but not the actual declaration. Just change it back from what I changed.
sure Adam, this is the code so far with the help from betawar. Thanks BetaWar by the way. I changed the return values and removed an extra bracket that wasn't needed (i think)It is still not fully working but it is now calling the second function but it just writes 'Not on shelf' for each line??
CODE
var bookArray = ['Framley Parsonage 1st Ed', 'Lady, Don\'t Fall Backwards', 'How to Win Friends 2nd Ed ', 'The Death of Harry Potter', 'The Kama Sutra (unexpurgated)', 'Little Noddy Goes to the Moon', 'Life of Tristram Shandy 1st ed', 'Remembrance of Things Past', 'On Her Majesty\'s Secret Service', 'The Wind-up Bird Chronicle', 'Last Exit to Birmingham', 'Love in the Time of Cholera', 'Java for Dummies 2nd Ed', 'The French Revolution', 'She Married a Duke', 'The Works of Shakespeare', 'A Tale of Two Cities', 'The Tailor of Gloucester', 'The Diary of a Nobody', 'The A to Z of Loving'];
It is still not fully working but it is now calling the second function but it just writes 'Not on shelf' for each line??
Err, sorry let me explain a little better.
Let's take dueArray[0]. dueArray[0] is equal to 0. currentDate (which was equal to 300 before but now isn't in your code for some reason??) is then subtracted form dueArray[0] and assigned to dateDue. So dateDue is now equal to -300.
Do that calculation with every number in your array and you'll see that dateDue will never be equal to 300. And therefore will always print "not on shelf."