My little quote project!

C H A L K
3 min readNov 15, 2022

It’s funny how my brain stops when I think of something, like how I should start this code.

So I’m VERY late updating my progress, but I swear every time I wake up I always check my code to see if I can find the answer! AND YES, FINALLY I FOUND THE PROBLEM IN MY PROJECT! (For 3 days I’m very eager to know what’s the problem, and I’m thankful for the feedbacks Michie!) More of this below!

So for the topics that I learned this past three days!

CREATING ARRAY WITH AN ARRAY LITERAL

BASIC OPERATORS

CONDITIONAL STATEMENTS (IF AND ELSE)

I’ll use my project as an example so that i can explain it properly.

var quotes = [

"A rational person can find peace by cultivating indifference to things outside of their control.",

"Comfort and routine are the enemies of creativity.",

"The only failure is not to try.",

"Great art is the outward expression of an innerlife in the artist, and this innerlife will result in his personal vision of the world.",

"These pains you feel are messengers. Listen to them."

]

// Here I created an array literal for the quotes since I have 5 quotes that are consider strings, they are separated with commas that will be hold in square brackets

// so why did I use an array? Simple, I want to store the quotes here so that I can organize the data that i will link to my variable called userMood

// NOTE count from array starts at 0 and I have 4 index (0-1-2-3-4)


// user will choose mood then type it into the variable called userMood
// "Anxious"
// "Silly"
// "Optimistic"
// "Calm"
// "Sad"

// Here the user choose the mood "Optimistic", so we expect a quote that is linked to my array
var userMood = "Optimistic"


// I use a conditional statement called "if statement" where if the userMood is "Optimistic", it should print the quote related to that.

// And also I used a comparison operators which is the (==) where it checks the equality of the value, in our case we want to compare the two strings (one from userMood and the other from the array) if they are equal then it will return as true, therefore it will print!
if userMood == "Calm" {
print("The quote according to your mood is, " + quotes[0])
}

// This is the exciting part, because I'm literally begging myself to check every resources i can read about this!

// I was wondering how I could access the other quotes in my arrays if the user did not select the mood that I was expecting. We don't want to create another variable and if statement for every quote.

// So this is where the "else statements" shine, we will make a condition where if the user chooses a mood, it will process the code inside the body of our "if statement" and if the code is evaluated, it will stop at the mood the user chose, then it will be printed!

// In our print statement we have a string that is added to our variable called "quotes" with a square brackets indicating their place in the index

else if userMood == "Silly"{
print("The quote according to your mood is, " + quotes[1])
}
else if userMood == "Optimistic"{
print("The quote according to your mood is, " + quotes[2])
}
else if userMood == "Calm"{
print("The quote according to your mood is, " + quotes[3])
}
else if userMood == "Sad"{
print("The quote according to your mood is, " + quotes[4])
}

// Since the user choose the mood "Optimistic", It should print like this
"The quote according to your mood is, The only failure is not to try."

--

--