www.webdeveloper.com
Results 1 to 5 of 5

Thread: JavaScript to jQuery?

  1. #1
    Join Date
    Oct 2010
    Posts
    17

    JavaScript to jQuery?

    How could i go about turning this JavaScript into jQuery format??

    Code:
    // JavaScript Document
    
    var CORRECTANS = 0;
    var WRONGANS = 0;
    
    function DoMath(oper)
    {
    	var fnum = parseInt(document.getElementById('fnum').value);
    	var snum = parseInt(document.getElementById('snum').value);
    	var xnum = parseInt(document.getElementById('xnum').value);
    	
    	switch(oper)
    	{
    		//Add
    		case 1:		    
    			JustDoIt((fnum+snum), xnum);
    		break;
    		
    		//Sub
    		case 2:
    			JustDoIt((fnum-snum), xnum);
    		break;
    		
    		//Mul
    		case 3:
    			JustDoIt((fnum*snum), xnum);
    		break;
    		
    		//Div
    		case 4:
    			JustDoIt((fnum/snum), xnum);
    		break;	
    	}
    	 
    }
    
    //numa: this is the correct answer
    //numb: this is what the online user supplied us with
    function JustDoIt(numa, numb)
    {
    	var result = document.getElementById('resultDiv');
    	if(numa == numb)
    	{
    		++CORRECTANS;
    		result.style.backgroundColor="#0f0";
    		if(CORRECTANS == 5){
    			result.innerHTML = "You Win!";
    		}
    		else {
    			result.innerHTML = numa;
    		}
    	}
    	else
    	{
    		++WRONGANS;
    		CORRECTANS = 0;
    		result.style.backgroundColor="#f00";
    		if(WRONGANS == 3){
    			result.innerHTML = "You lose";
    		}
    		else {
    			result.innerHTML = numa;
    		}
    		
    	}	
    }

  2. #2
    Join Date
    Dec 2005
    Posts
    2,984
    Is there a need? If it works now, then it'll work whether or not the jQuery library is included on the page.

    Realistically, there are 10 lines that could be altered to fit 'jQuery Syntax', but when you think about it, the jQuery methods would just end up calling the exact same low-level DOM methods anyway, so the code you have in your post would technically be more efficient than if you rewrote it with jQuery methods.....
    Last edited by aj_nsc; 08-23-2011 at 01:17 PM.

  3. #3
    Join Date
    Jul 2003
    Location
    The City of Roses
    Posts
    2,503
    I agree with aj_nsc. jQuery eases things like DOM manipulation, events, effects, and ajax, but the code you posted does very little of those things. jQuery won't be much help in this case.
    for(split(//,'))*))91:+9.*4:1A1+9,1))2*:..)))2*:31.-1)4131)1))2*:3)"'))
    {for(ord){$i+=$_&7;grep(vec($s,$i++,1)=1,1..($_>>3)-4);}}print"$s\n";

  4. #4
    Join Date
    Oct 2010
    Posts
    17
    I greatly appreciate the input!!!

  5. #5
    Join Date
    Oct 2010
    Posts
    17
    Hey fellas! Would any of you be able to help me out with this thread: http://www.webdeveloper.com/forum/sh...d.php?t=250674 ?

    Would greatly appreciate it!!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles