Design comparison
Solution retrospective
You guys think which way is better to generate random advice? get random numbers and then according to API rules to fetch the corresponding advice or refresh the API and get the random advice? CSS intermediate to advance learning, do you have any advice? I feel CSS is even difficult to master than javascript.
Community feedback
- @md5daltonPosted about 2 years ago
Hello..π
It's preferable to use the functionality provided by the API since you don't need to create your own logic unless you have a very specific reason to do so.
Here are some of the drawbacks of writing your own logic in this case:
- You don't know the total number of advice objects, so some of them that are out of the max value you provided will never be part of the results.
function getRandomNumber(){ return Math.floor(Math.random()*224+1); }
- You are reinventing the wheel, of which is a waste of effort to work on code which you don't necessarily have to.
1@xingxing-progPosted about 2 years ago@md5dalton well, I want I can get a random advice when I clicked the dice. But if I use their random advice, I couldn't get it immediately after I clicked the dice. I don't know whether I understood it well. Thanks for pointing out.
0@md5daltonPosted about 2 years ago@xingxing-prog That has to do with the browser caching the response. You can prevent that by passing additional options to fetch:
const response = await fetch(url, { cache: "no-cache" })
I forgot to mention that earlier.
0@xingxing-progPosted about 2 years ago@md5dalton Thank you so much. I considered this option, but I don't know how to use it. I just took the course about http fetch. Thanks for pointing out. Can you give courses or projects or tips for mastering promise and async, I feel it's a very important topic. I learned some courses, but I still feel I am outsiders. Do you have any advice about learning CSS, I feel the intermediate to advance is kind of difficult. I wish I had learnt some design courses. Thank you.
0@md5daltonPosted about 2 years ago@xingxing-prog you're welcome. I noticed you've implemented itπ
Here are some resources if you want to check them out:
An interactive course from FreeCodeCamp for basic CSS:
Youtube videos from Traversy Media:
CSS
Javascript
0@xingxing-progPosted about 2 years ago@md5dalton Yes, I did. I agree to your opinion(using the API method unless if it's must add some other functions) totally. Because I have considered if the advices' number is very huge, moreover, less codes less mistakes and higher speed. Thanks for your advice and resource.
0
Please log in to post a comment
Log in with GitHubJoin our Discord community
Join thousands of Frontend Mentor community members taking the challenges, sharing resources, helping each other, and chatting about all things front-end!
Join our Discord