For my javascript project, I have a list that looks like this:
<li id="1">101.33, "book name 1"</li>
<li id="2">600.01, book name 2</li>
<li id="3">001.11, book name 3</li>
etc...
Of which I am supposed to do the following:
- Remap the bullet list entries to a new (consistent) tag type (your choice – make it look pretty!).
- For entries between 100 and 200, add 100 to the Dewey decimal number.
- For entries between 400 and 500, add 200 to the Dewey decimal number.
- Entries between 850 and 900 need to have 100 removed from the Dewey decimal number.
- Entries between 600 and 650 need to have 17 added to the Dewey decimal number
- For items that get changed, append “changed” to the record.
- For items that do not get changed, append “no change” to the record.
- For records that are incorrect, append “invalid record” to the record
But I'm not sure how to go about it. I want to target any number in the body, or within a list item. Right now I have this:
var z = document.body.li.innerHTML;
if (z >+ 100 && z <= 200)
{
var q = z + 100;
document.body.li.innerHTML=q;
}
}
Can anyone point me in the right direction of the best approach to do this in javascript? Should I be using find/replace instead?
EDIT: Attempted to amend the last ternary if else statement in David Thomas' code. Can't seem to get it to work:
//define valid record number as at-least-one-integer.at-least-one-integer
var reggie = /\d+(.)+d/
if (_newText = reggie) {
'Invalid Record';
}
else if (_newText === a[textProp]) {
'no change';
}
else(_newText != a[textProp]) {
'changed';
}
+ ')';