| 29 | |
| 30 | |
| 31 | function initDraw(){ |
| 32 | var svg = buggContainer.append('svg') |
| 33 | .attr({width: width, height: height}) |
| 34 | .style({position: 'absolute', top: '0px'}) |
| 35 | |
| 36 | var bugs = [ |
| 37 | { img: 'emotes/pose_moth.gif', |
| 38 | pos: [width*.01, height*.05], |
| 39 | wrong: 'var salesPlusFour = "4" + sales;', |
| 40 | right: 'var salesPlusFour = 4 + sales;'}, |
| 41 | { img: 'emotes/pose_moth2.gif', |
| 42 | pos: [width*.75, height*.05], |
| 43 | wrong: 'for (var i = 0; i < 10 i++)', |
| 44 | right: 'for (var i = 0; i < 10; i++)'}, |
| 45 | { img: 'emotes/pose_moth.gif', |
| 46 | pos: [width*.75, height*.75], |
| 47 | wrong: 'if (newBug == oldBug)', |
| 48 | right: 'if (newBug === oldBug)'}, |
| 49 | { img: 'emotes/pose_moth2.gif', |
| 50 | pos: [width*.02, height*.75], |
| 51 | right: 'var total += currentValue', |
| 52 | wrong: 'var total = +currentValue'}, |
| 53 | { img: 'emotes/pose_moth.gif', |
| 54 | pos: [width*.50, height*.50], |
| 55 | wrong: 'isBetween = min < next < max', |
| 56 | right: 'isBetween = min < next && next < max'}, |
| 57 | { img: 'emotes/pose_moth2.gif', |
| 58 | pos: [width*.0, height*.4], |
| 59 | wrong: 'var x = Math.Sin(θ)', |
| 60 | right: 'var x = Math.sin(θ)'}, |
| 61 | { img: 'emotes/pose_moth.gif', |
| 62 | pos: [width*.40, height*.10], |
| 63 | wrong: 'obj.function()', |
| 64 | right: 'obj && obj.function && obj.function'}, |
| 65 | ] |
| 66 | |
| 67 | bugs.forEach(function(d){ |
| 68 | d.correct = false |
| 69 | d.img = _.sample(['images/emotes/pose_moth.gif','images/emotes/pose_moth2.gif']) |
| 70 | d.t = Math.random() |
| 71 | d.visable = false |
| 72 | d.spawned = false |
| 73 | }) |
| 74 | |
| 75 | function addBug(d, prev){ |
| 76 | if (!d || d.visable) return |
| 77 | |
| 78 | d.visable = true |
| 79 | |
| 80 | d.div = buggContainer.append('div.bugg') |
| 81 | |
| 82 | d.imgEl = d.div.append('img.bug-img').attr('src', d.img) |
| 83 | |
| 84 | d.qcontainer = d.div.append('div.q-container') |
| 85 | d.qcontainer |
| 86 | .dataAppend(_.shuffle([d.right, d.wrong]), 'div.awnser') |
| 87 | .text(ƒ()) |
| 88 | .on('click', function(e){ |