View Single Post
Old 06-28-2012, 02:14 AM   PM User | #7
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,200
Thanks: 59
Thanked 3,996 Times in 3,965 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
But you know, it would be better to keep the words paired, rather than depending on parallel arrays that could easily get out of sync. So:
Code:
<button onclick="nextWord(1)">Previous word</button>
<button onclick="showEnglish()">Answer</button>
<button onclick="nextWord(-1)">Next word</button>

<script type="text/javascript">
var words = [
    ["食べる",  "to eat"],
    ["読む",    "to read"],
    ["行く",     "to go"]
];
var wordCount = words.length;
var cnt=0;

function showEnglish()
{
    document.getElementById("english").innerHTML = words[cnt][1];
}
function nextWord( moveBy )
{
    cnt = ( cnt + wordCount + moveBy ) % wordCount;
    document.getElementById("japanese").innerHTML = words[cnt][0]
    document.getElementById("english").innerHTML='&nbsp;';
}
nextWord(0); // get it started
</script>
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Users who have thanked Old Pedant for this post:
meridian (06-28-2012)