Hello everyone,
I created a random star sign and quote generator!
I initially decided to use the if statement to generate my quote!
However after speaking to my tutor he advised me to try another method to achieve the same results!
That’s when I came up with the Loop method (as you can see it’s commented out at the bottom of the file).
Feel free to provide any feedback on how I can improve or make this code better.
Thanks in advance.
Project link
I hope you enjoyed this project 
1 Like
your fast and like your posts
Hello, and welcome to the forums!
Nice job completing the project. Since you requested feedback, this could be greatly simplified:
if (newSign === 'Capricorn') {
console.log(`Congratulations your star sign is Capricorn and your random quote is: ${newQuote}`)
} if (newSign === 'Aquarius') {
console.log(`Congratulations your star sign is Aquarius and your random quote is: ${newQuote}`)
} if (newSign === 'pisces') {
console.log(`Congratulations your star sign is pisces and your random quote is: ${newQuote}`)
} if (newSign === 'Aries') {
console.log(`Congratulations your star sign is Aries and your random quote is: ${newQuote}`)
} if (newSign === 'Taurus') {
console.log(`Congratulations your star sign is Taurus and your random quote is: ${newQuote}`)
} if (newSign === 'Gemini') {
console.log(`Congratulations your star sign is Gemini and your random quote is: ${newQuote}`)
} if (newSign === 'Cancer') {
console.log(`Congratulations your star sign is Cancer and your random quote is: ${newQuote}`)
} if (newSign === 'Leo') {
console.log(`Congratulations your star sign is Leo and your random quote is: ${newQuote}`)
} if (newSign === 'Virgo') {
console.log(`Congratulations your star sign is Virgo and your random quote is: ${newQuote}`)
} if (newSign === 'Libra') {
console.log(`Congratulations your star sign is Libra and your random quote is: ${newQuote}`)
} if (newSign === 'Scorpio') {
console.log(`Congratulations your star sign is Scorpio and your random quote is: ${newQuote}`)
} if (newSign === 'Sagittarius') {
console.log(`Congratulations your star sign is Sagittarius and your random quote is: ${newQuote}`)
}
Just like you did for the newQuote
variable, you could include newSign
in the string so that the entire chain of if
s could be removed
Hey thanks the feedback!
When you said include the newSign string did you mean like this below?
const newSign = signs[Math.floor(Math.random() * signs.length)];
console.log(`Your new star sign is: ${newSign}`);
const newQuote = quotes[Math.floor(Math.random() * quotes.length)];
console.log(`Your new quote for 2021 is: "${newQuote}"`);
Thanks again!
Hello,
What I mean is that you could just combine it with one console.log() if you still want it to be how it was already
console.log(`Congratulations your star sign is ${newSign} and your random quote is: ${newQuote}`);
You’re allowed to use multiple expressions in a template literal.
2 Likes
that is what i was gonna say