JSFiddle - React, Tailwind, and code Playground

by japaneselanguagefriend

HTML

<ul>
    <li><img src="http://www.dearbornfreepress.com/wp-content/uploads/2010/10/the_letter_A.jpg" />a</li>
    <li><img src="http://2.bp.blogspot.com/-FJetGzG7c5g/TMrz-HIOXfI/AAAAAAAALKA/IkWwq_Pb6yI/s1600/65038_T-letter_lg.gif" />t</li>
    <li><img src="http://2.bp.blogspot.com/-RO9UV9XcQRY/ThjQHDHumBI/AAAAAAAAAME/xc0tw16OY80/s1600/letter+E.jpg" />e</li>
<ul>
    
<br /><br />

<input type="text" id="test" />
    
<br /><br />
Type the text in the boxes into the input, and see them change.

CSS

li {position: relative; height: 100px; width: 160px; display: inline-block; background: red; text-align: center; vertical-align: middle; margin: 20px;}


img {height: 100px; width: 160px;}

JavaScript

var text = ['ta', 'be', 'ru'];
var stepsize = 2;

var happy = ['http://www.vendian.org/howbig/UnstableURLs/letter_a_poster.png',
             'http://chineseknotting.org/projects/knotty/T-carrick.jpg',
             'http://etc.usf.edu/presentations/extras/letters/varsity_letters/38/17/E-400.png'
            ];

var grumpy = $('img').map(function(){ return this.src; }).get(); //gets the original images from the HTML

$("#test").on('keyup', function() {
    var typed = this.value;
    $.each(text, function(index, item) {
        if (typed.substring(stepsize*index, (stepsize*index)+stepsize) == text[index]) {
            $('li', 'ul').eq(index).find('img').attr('src', happy[index]);
        }else{
            $('li', 'ul').eq(index).find('img').attr('src', grumpy[index]);
        }
    });
});