# Random question with song

**URL:** https://discourse.processing.org/t/random-question-with-song/28853
**Category:** Coding Questions
**Tags:** homework
**Created:** [March 25, 2021, 11:40pm UTC](https://discourse.processing.org/t/random-question-with-song/28853 "2021-03-25T23:40:39Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Ellen](https://avatars.discourse-cdn.com/v4/letter/e/dfb087/32.png) [@Ellen](https://discourse.processing.org/u/Ellen)
#### Post date: [March 25, 2021, 11:40pm UTC](https://discourse.processing.org/t/random-question-with-song/28853/1 "2021-03-25T23:40:39Z")

</div>

I’m stuck that I cannot make a song match a random question.  
Can anybody help, please?

````auto
import processing.sound.*;
SoundFile file;

String[] Texts = {
  "Question A", 
  "Question B", 
  "Question C", 
  "Question D", 
  "Question E", 
  "Question F", 
  "Question G"
};

String[] RightAnswer = {
  "Yes", 
  "No", 
  "Yes", 
  "No", 
  "No", 
  "Yes", 
  "No"
};

int n = int (random(0, 6));

//String myText;
int totalWrong = 0;
int totalCorrect = 0;
//int question = 0;
//String correctAnswer;
//String WrongAnswer;
//int True= 0;
//int False= 0;

void setup() {
  size(800, 400);
  background(255);
  smooth();
  ellipseMode(CENTER);
}

void draw() {
  // draw() runs 60 times per second again and again

  // we clear the screen to WHITE  
  background(255);

  // we show stuff 
  noStroke();

  //Button 1
  fill(255, 20, 40);
  if (button1()) 
    fill(0, 255, 0); 
  ellipse(320, 100, 20, 20);
  text("YES", 320+22, 100);

  //Button 2
  fill(255, 20, 40);
  if (button2()) 
    fill(0, 255, 0); 
  ellipse(420, 100, 20, 20);
  text("NO", 420+22, 100); 

  fill(0);
  rect(width/2, height/2, 300, 100);
  textSize(20);
  text(Texts[n], 10, 30);
  if (Texts[0]), file.play();
  text(RightAnswer[n], 10, 30+22);```
````

---

<div class="post-metadata">

### Author: ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)
#### Post date: [March 26, 2021, 9:29am UTC](https://discourse.processing.org/t/random-question-with-song/28853/2 "2021-03-26T09:29:24Z")

</div>

Do you want to play a different song for each Question?

Or the same song for each new question?

**When you want to play a different song for each Question**

When you want to play a different song for each Question:

Make an Array, the array has the same length like `Texts ` and `RightAnswer `  
which means the song for Texts number 0 is also number 0.

before setup()  
`SoundFile[] myCoolSongs = new SoundFile[7];`

fill the array in setup()

```auto
myCoolSongs[0] = new SoundFile(this, “will.wav”);
myCoolSongs[1] = new SoundFile(this, “reel.wav”);
myCoolSongs[2] = new SoundFile(this, “hitaa.wav”);

```

and so on.

**NOW** , when you ask question number n play also the song number n:

`myCoolSongs[n].play();`

then you don’t need `if`
