<pre><pre lang="HTML"> <pre> <pre><!Doctype html> <html> <head> <link rel="stylesheet" href="assignment-Jasmine.css"> <title>JavaScript to JQuery</title> <script src="https://code.jquery.com/jquery-3.5.1.min.js" integrity="sha256-9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0=" crossorigin="anonymous"> </script> <style> td{ padding-top: 5px; padding-bottom: 5px; padding-right: 20px; padding-left: 20px; } .wrong { background-color: #fa8072; } .right { background-color: transparent; } </style> </head> <body>
Try to see if you can do the math
</body> </html>
<pre lang="Javascript"> <pre> (function( math ) { 'use strict'; var tr = math.querySelectorAll( 'tr' ), td = math.querySelectorAll( 'td' ), inp = math.querySelectorAll( 'input' ), totals = [], c; for ( c = 0; c < tr.length; c ++ ) { totals.push( parseFloat( td[ c * 3 ].textContent ) + parseFloat( td[ c * 3 + 1 ].textContent ) ); inp[ c ].value = ' '; inp[ c ].addEventListener( 'blur', check_answer( c ), false ); } function check_answer( c ) { inp[ c ].onblur = function() { if( inp[ c ].value == totals[ c ] ) { tr[ c ].classList.add( 'right' ); } else { tr[ c ].classList.remove( 'right' ); tr[ c ].classList.add( 'wrong' ); } } } }( document ) ); $( window ).unload(function(math) { });
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)