Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/Save_Mathematics/P4/map412m10/map412m10a12/js/lesson.js
blob: cbde1ebcb29c1b91aaf0ec271d8160957b945f1f (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
71
72
73
74
75
//problems in computing the area and perimeter of rhombi

var something = ['yard','field','parking lot','floor','lake','pasture'];
var units = ['mm2','cm2','dm2','m2','dam2','hm2','km2'];
var factor = [0,100,10000,1000000,100000000,1000000000,1000000000000]
var nunits = units.length;

function generate_decimal(min,max) {
  n = Math.random()*(max-min)+min;
  ntxt = n + ' ';
  point = ntxt.indexOf('.');
  whole = ntxt.substring(0,point-1)
  decimal = ntxt.substring(point+1,point+4)
  return whole + '.' + decimal;
};

function generate_operand(min,max) {
  return Math.random()*(max-min) + min;
};

function shift(i1,i2,amount){
  if(i2>i1){
      f = factor[i2-i1];
      return amount/f;
  }else{
      f = factor[i1-i2];
      return amount*f;
  }
};

function generate_opportunity(questions){
    //build quiz.js
    quiztxt = '';
    for (q=0;q<questions;q++){
        type = Math.random();
        if(type < 0.5){
            //determine area from base and altitude
            base = parseInt(generate_operand(1,100));
            altitude = parseInt(generate_operand(1,100));
            area = base*altitude;
            quiztxt = quiztxt+'{ ques: "The base and altitude of a rhombus are '
            quiztxt = quiztxt+base+" "+altitude+". What is it's area?"+'"';
            quiztxt = quiztxt+", ans:'"+area+"'},\n"
        }else{
            //determine perimeter from sides
            side1 = parseInt(generate_operand(1,100));
            side2 = parseInt(generate_operand(1,100));
            perimeter = 2*(side1+side2);
            quiztxt = quiztxt+'{ ques: "The sides of a rhombus are '
            quiztxt = quiztxt+side1+" "+side2+". What is it's perimeter?"+'"';
            quiztxt = quiztxt+", ans:'"+perimeter+"'},\n"
        };
    };
    return quiztxt;
};

function initialize(karma) {
    quiztxt = generate_opportunity(12);
    url = window.location+"";
    $('<div id="txtMain" />')
        .load('http://localhost:8008/cgi-bin/getFile.py',
        {'filename':'content/Mathematics/map412m10/map412m10a12/a.txt'})
        .appendTo('#content');
    $('<div id="workArea" />')
        .load('http://localhost:8008/cgi-bin/writeQuiz.py',
        {'activity':url,'text': quiztxt});
};

function startGame(karma) {
    $('<div id="quizArea" />')
        .appendTo('#content')
        .jQuizMe(quiz,options)
};

setUpLesson(initialize, startGame);