xxxxxxxxxx
92
i = 0;
let arr = []
function preload(){
psych = loadJSON("Psych.json")
afinn = loadJSON("afinn111.json")
}
function setup() {
createCanvas(400, 400);
let foo = new p5.Speech(); // speech synthesis object
foo.speak(psych.personality_test[i]); // say something
// This is where we are trying to take the array of personality questions and push them to the typing app, but it is not accepting the array for some reason
var txt = select('#txt');
txt.input(typing);
typing();
}
function draw() {
background(220);
textAlign(CENTER)
textStyle(ITALIC)
textSize(20)
text(psych.personality_test[i], 100, 100, 200, 200);
}
function mousePressed(){
let foo = new p5.Speech();
let val = round(random(psych.personality_test.length))
//console.log(psych.personality_test)
foo.speak(psych.personality_test[val]);
i = val
txt.value = psych.personality_test[i];
// call typing only when it's a yes
//if (yes){
typing()
// }
}
// This is the typing app which allows the words in each of the questions to be scored by the Score3.json file.
function typing() {
txt.value = psych.personality_test[i]
let textinput = txt.value;
let words = textinput.split(/\W/);
console.log(words);
let scoredwords = [];
let totalScore = 0;
for (let i = 0; i < words.length; i++) {
var word = words[i].toLowerCase();
if (afinn.hasOwnProperty(word)) {
let score = afinn[word];
console.log(word, score);
totalScore += Number(score);
scoredwords.push(word + ': ' + score + ' ');
// push total score to global Array 'arr'
arr.push(totalScore)
console.log(arr)
if (arr.length==20){
music()
}
}
}
var scorePar = select('#scoreP');
scorePar.html('score: ' + totalScore);
var comp = select('#comparativeP');
comp.html('comparative: ' + totalScore / words.length);
var wordlist = select('#wordlistP');
wordlist.html(scoredwords);
}
function music() {
}