xxxxxxxxxx
62
let input, submitButton, prompt;
let strings=[];
function preload() {
strings = loadStrings("quotes.csv")
}
function setup() {
if (strings == null) {
print("failed to load the file, stopping here");
}
print("strings array contains this many lines: " + strings.length);
// create canvas
createCanvas(710, 400);
input = createInput();
input.position(20, 100);
input.size(400);
submitButton = createButton('submit');
submitButton.position(input.x + input.width, 100);
submitButton.mousePressed(prompting);
// all the prompts in an array
let allThePrompts = split(strings[1], ",");
print (allThePrompts); //it has 5 prompts and they are all split. nice!!!
// x is the index of the random prompt in the promt array
let X=int(random(allThePrompts.length));
print(X);
// foo is the random prompt
let foo = allThePrompts[int(random(5))];
print (foo);
//choosing 1 of the prompts from an array
prompt = createElement('h2',foo);
prompt.position(20, 5);
textAlign(CENTER);
textSize(50);
}
function prompting() {
input.hide();
// ? not working: how to hide the button: button.hide();
prompt.html('Thank you for your response ! Hopefully it made your day a little better ^^ ');
input.value('');
}