Note that there are some explanatory texts on larger screens.

plurals
  1. POJavascript conditional find/replace
    primarykey
    data
    text
    <p>For my javascript project, I have a list that looks like this:</p> <pre><code>&lt;li id="1"&gt;101.33, "book name 1"&lt;/li&gt; &lt;li id="2"&gt;600.01, book name 2&lt;/li&gt; &lt;li id="3"&gt;001.11, book name 3&lt;/li&gt; etc... </code></pre> <p>Of which I am supposed to do the following:</p> <ol> <li>Remap the bullet list entries to a new (consistent) tag type (your choice – make it look pretty!). </li> <li>For entries between 100 and 200, add 100 to the Dewey decimal number. </li> <li>For entries between 400 and 500, add 200 to the Dewey decimal number. </li> <li>Entries between 850 and 900 need to have 100 removed from the Dewey decimal number. </li> <li>Entries between 600 and 650 need to have 17 added to the Dewey decimal number </li> <li>For items that get changed, append “changed” to the record. </li> <li>For items that do not get changed, append “no change” to the record. </li> <li>For records that are incorrect, append “invalid record” to the record </li> </ol> <p>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:</p> <pre><code>var z = document.body.li.innerHTML; if (z &gt;+ 100 &amp;&amp; z &lt;= 200) { var q = z + 100; document.body.li.innerHTML=q; } } </code></pre> <p>Can anyone point me in the right direction of the best approach to do this in javascript? Should I be using find/replace instead?</p> <p>EDIT: Attempted to amend the last ternary if else statement in David Thomas' code. Can't seem to get it to work:</p> <pre><code>//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'; } + ')'; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload