mercredi 31 juillet 2019

How Do I Make My If Statement Run Correctly?

Below is my code. By the prompt "Do you enjoy fiction books?" the code is not working surrounding the if other == true statement (if no is entered). Any help would be appreciated!! I am unsure what part of the if statement needs to be fixed and I would really like to see this program working as I am 15 and the hours I have put into it is a lot!

<!DOCTYPE html>
<html>
<head>
    <title>Chatbot Charlie</title>
    <meta name='generator' content='notepad++'/>
</head>
<body>
<script>
var FantasyArray = ["A Song Of Ice And Fire by George R.R. Martin","The Lion, The Witch, and The Wardrobe by C.S. Lewis","American Gods by Neil Gaiman", "Good Omens by Terry Pratchett & Neil Gaiman",];
var ScienceFictionArray = ["1984 by George Orwell","Brave New World by Aldous Huxley","The Three Body Problem by Cixin Liu", "Ender's Game by Orson Scott Card",];
var RomanceArray = ["Pride and Prejudice by Jane Austen","Outlander by Diana Gabaldon","The Mister by E.L. James", "The Notebook by Nicholas Sparks",];
var ActionArray = ["City of Bones by Cassandra Clare","The Hunger Games by Suzanne Collins","Divergent by Veronica Roth","The Lightning Thief by Rick Riordan",];
var MysteryArray = ["Big Sky by Kate Atkinson","The Girl With The Dragon Tattoo by Steig Larsson","Gone Girl by Gillian Flynn", "In The Woods by Tana French",];
var OtherArray = ["Think And Grow Rich by Napoleon Hill", "The 4 Hour Work Week by Tim Ferriss","The Secret by Rhona Byrne", "10% Happier by Dan Harris", "Edmonds Cookbook by Edmonds Cooking", "Going Paleo by Pete Evans", "Fresh Start Feel Good by Nadia Lim", "Homegrown Kitchen by Nicola Galloway", "How Not To Die by Gene Stone and Michael Greger", "Intuitive Eating by Evelyn Tribole",];

alert("Welcome To Chatbot Charlie. Here we will help you find a storybook to read!");}

function getRndFromArray(arrayName){                                
return arrayName[Math.floor(Math.random()*arrayName.length)]; 
}   
    var strng = prompt("Do you like reading? Yes or No?") ; // first question asking if you like reading or not 
    var likesreading = strng.includes("Yes"); //string include "yes" true or false
    var dislikesreading = strng.includes("No"); //string include "no" true or false         

if (likesreading == true) // if string includes yes and therefore says you like reading then...
{
var likesreadingArray = [                                                                                                                       
"So do I!",
"I do enjoy reading too, wish I had more time to do it",
"I do like reading",];

alert("You do like reading! "+getRndFromArray(likesreadingArray)); //get random reply from array which adds to alert
}   

        else if (dislikesreading == true)   //if string includes no and therefore says you like reading then...
        {
        var dislikesreadingArray = [
        "Oh okay, you must have other hobbies. I'm sure reading could become one of yours!",
        "I used to dislike it too.",
        "Maybe you just haven't read a good book yet",];
        alert("You don't like reading! "+getRndFromArray(dislikesreadingArray));    //get random reply from array which adds to alert
        }

            else //if no option is inputed this set of code will run
            {
            alert("A lot of people are undecided on this too! Definitely depends on what book you are reading")
}
var again;
do {
  var strng = prompt(
    "Do you enjoy fiction books? Yes or No?");
  var fiction = strng.includes("Yes");
  var other = strng.includes("No");

  if (fiction == true) {
    var strng = prompt(
      "What genre do you prefer from the following? Fantasy, Science Fiction, Rommance, Action, Mystery"
    );
    var fantasy = strng.includes("Fantasy");
    var sciencefiction = strng.includes("Science Fiction");
    var romance = strng.includes("Romance");
    var action = strng.includes("Action");
    var mystery = strng.includes("Mystery");
    if (fantasy == true) {
      alert("I think you will enjoy " + getRndFromArray(FantasyArray));
    } else if (sciencefiction == true) {
      alert("I think you will enjoy " + getRndFromArray(ScienceFictionArray));
    } else if (romance == true) {
      alert("I think you will enjoy " + getRndFromArray(RomanceArray));
    } else if (action == true) {
      alert("I think you will enjoy " + getRndFromArray(ActionArray));
    } else if (mystery == true); {
      alert("I think you will enjoy " + getRndFromArray(MysteryArray));
    }

if(other == true) {
      alert("Read " +getRndFromArray(OtherArray));}


     //if no option is inputed this set of code will run
      else {
        var again = prompt(
          "You have not told me whether you like fiction books. Would you like to try again? Yes or No?"
        );
      }
    } // prompt relating to do while loop
  }
} while (again === "Yes");

alert("Happy Reading!");}

</script>
</body>
</html>

Aucun commentaire:

Enregistrer un commentaire