repl.it
@meganvieno/

Spirit Animal MATH FINAL

JavaScript

No description

fork
loading
main.js
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
76
77
78
79
80
81
82
83
84
85
86
87

 /* Prompts */ 
  
  var question1 = prompt("a,b,c or d? ");
  var question2 = prompt("a,b,c or d? ");
  var question3 = prompt("a,b,c or d? ");
  var userNumber = prompt("Pick any number between 1-20");
  var userObject = prompt("Give me the name of an object");
  
  console.log("user choices:  " + question1, question2, question3);

var answer = new Array(question1, question2, question3); 
console.log("choices as an array: " + answer);

/* Prompts to numbers*/ 
var toNumbers = [];
function answersToNumbers(){
  for(var i =0; i<answer.length; i++){
   if(answer[i] === 'a' || answer[i] === 'A'){
     toNumbers = toNumbers + 2; 
   } else if (answer[i] === 'b' || answer[i] === 'B'){
      toNumbers = toNumbers + 1; 
   } else if (answer[i] === 'c' || answer[i] === 'C'){
     toNumbers = toNumbers + 1; 
   } else if (answer[i] === 'd' || answer[i] === 'D'){
      toNumbers = toNumbers + 2; 
   }
 } /*split and return as integers*/ 
 toNumbers = toNumbers.split('').map(function(item) {
  return parseInt(item, 10);
});

 console.log("convert to numbers:  " + toNumbers);
}

/* add up the numbers in the toNumbers array*/ 
var oneNum= function(n,userNumber){
  for(var i =0; i < n.length; i++ ) {
    oneNum = n.reduce(function(a,b){ return a+b})
  }
  console.log("added up all the numbers:  " + (oneNum + userNumber) );
  return oneNum + userNumber;
}


/*User's object first letter*/
var object = userObject.charAt(0);
/*store totalNumber and first letter of the object in an arr*/ 

/*Use if/else and the arr elements to determine final image*/

function imageReturn(finalArr){
  if (finalArr[0] >=0 && finalArr[0] <= 124 && finalArr[1] === /^[a-mA-M]+$/) {
    return ("image 1");
  } else if (finalArr[0] >=0 && finalArr[0] <= 124 && finalArr[1] === /^[n-zN-Z]+$/) {
    return ("image 5");
  } else if (finalArr[0] >=125 && finalArr[0] <= 249 && finalArr[1] === /^[a-mA-M]+$/) {
    return ("image 2");
  } else if (finalArr[0] >=125 && finalArr[0] <= 249 && finalArr[1] === /^[n-zN-Z]+$/) {
    return ("image 4");
  } else if (finalArr[0] >=250 && finalArr[0] <= 374 && finalArr[1] === /^[a-mA-M]+$/) {
    return ("image 3");
  }else if (finalArr[0] >=250 && finalArr[0] <= 374 && finalArr[1] === /^[n-zN-Z]+$/) {
    return ("image 3");
  }else if (finalArr[0] >=375 && finalArr[0] <= 498 && finalArr[1] === /^[a-mA-M]+$/) {
    return ("image 4");
  }else if (finalArr[0] >=375 && finalArr[0] <= 498 && finalArr[1] === /^[n-zN-Z]+$/) {
    return ("image 2");
  }else if (finalArr[0] >=499 && finalArr[0] <= 620 && finalArr[1] === /^[a-mA-M]+$/) {
    return ("image 5");
  }else if (finalArr[0] >=499 && finalArr[0] <= 620 && finalArr[1] === /^[n-zN-Z]+$/) {
    return ("image 1");
  } 
}




answersToNumbers(answer);
console.log(highLets);
console.log(lowLets);
var finalArr = new Array(oneNum(toNumbers,userNumber), object); 
console.log(finalArr);
imageReturn(finalArr);

Native Browser JavaScript