Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/examples/adding_up_to_10_old/js/adding_up_to_10.js~
blob: d5013fa8bcf15a81283fdaf66e76977f65854d14 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
$(document).ready(function(){
  
	var canvasDrawing = $("#canvasDrawing")[0];
	var ctxDrawing    = canvasDrawing.getContext("2d"); 
	
	var canvas    =$("#canvas")[0];
	var ctx       = canvas.getContext("2d"); 
	
	
	var path={
		images: "images/"
	};
	
	//f of functions, a "place" to put functions ;)
	var f= {
		rand: function ( lower, upper){
    		return Math.round ( Math.random() * (upper - lower) + lower );
		} 
	
	}
    //logic game
    var total, n0, n1, correct;
    var choice=new Array();
    
    total = f.rand( 3, 9 ); //the total
    n0 = total - f.rand(1, total - 1 ); //first number
    n1 = total - n1; //second number
	
	for (var i=0; i<3; i++) {
		choice[ i ] = f.rand( 3, 9 ); // generate the 3 options
	}
	correct = f.rand( 0, 2 );	//chose one option (correct option) and then put the correct value into it 
	choice[ correct ] = total;
	
	//
	var lang, gt;
	var supportedLangs = [ "en-US", "es-MX", "ne-NE", "he-IL"];
	function init( userLang ) {
		if (userLang===undefined)  {
			lang = $.localise.defaultLanguage.substr(0,2);
			for (var i=0; i < supportedLangs.length; i++) {
				if (supportedLangs[i].substr(0,2) == lang ) {
					lang = supportedLangs[i];
					$("input[@name='langSelector']:eq("+ i +")").attr("checked", true); 
					break;
				}
			}
		}else {
			lang = userLang;	
		}
		gt = new Gettext({ 'domain' : lang });
	
		//debug info	
		var l= ["choose an option", "Time", "Level", "Restart"];
		var s="";
		$.each( l, function( i, val ){
			s+=val+": "+ gt.gettext( val ) + " ";
		});
		$("#debug").html( s );
		
		//
	}
	
	$(":input[@name='langSelector']").change(function(){	
		init ( $("input[@name='langSelector']:checked").val() );
	});
	
	init();
	
});