Code Monkey home page Code Monkey logo

advice-generator-app's Introduction

Frontend Mentor - Advice generator app solution

This is a solution to the Advice generator app challenge on Frontend Mentor. Frontend Mentor challenges help you improve your coding skills by building realistic projects. The advice generator app generates a new piece of advice by clicking the dice icon.

Table of contents

Overview

The challenge

Users should be able to:

  • View the optimal layout for the app depending on their device's screen size
  • See hover states for all interactive elements on the page
  • Generate a new piece of advice by clicking the dice icon

Screenshot

Links

My process

Built with

  • Semantic HTML5 markup
  • CSS custom properties, Flexbox for styling
  • Mobile-first workflow
  • JavaScript

What I learned

Here are some of the code snippets I used from the resources I listed in the Useful Resources section below:

@media (hover: hover) {
  .dice-image:hover {
    box-shadow: -1px 1px 88px 12px rgba(82, 255, 168, 1);
    transition: all ease-in-out 0.3s;
  }
}

In the CSS snippet above, I used the @media (hover: hover) query to apply a box shadow and transition effect to the dice image when it is hovered over. This ensures that the hover styles are only applied on devices that support hover.

'use strict'

// Send request to the advice API
  fetch(apiUrl, { cache: "no-cache" })
    .then((response) => {

      // Check for errors and handle them
      if (!response.ok) {
        throw new Error("Network response was not ok");
      }

      // Parse the JSON response
      return response.json();
    })
    .then((response) => {
      // Extract the advice data from the response
      let data = response.slip;
      let dataId = data.id;
      let dataAdvice = data.advice;

      // Update the advice number and text in the DOM
      adviceNumber.innerHTML = `advice # ${dataId}`;
      adviceText.innerHTML = dataAdvice;
    })
    .catch((error) => {
      // Handle errors from the API request
      console.error("There was an issue with the API:", error);
      // display an error message to the user and give them the option to try again
    });

In the JavaScript snippet above, it's showed how to send a request to an API, parse the response, and handle any errors that may occur. I learned how to handle errors and display error messages to users, as well as how to extract data from a JSON response and update the DOM with that data.

Continued development

After finishing this project, I'd like to continue practicing with the fetch() method and working with external APIs. I also plan to build more apps that generate random content, as I find this type of interactivity to be both fun and challenging.

Useful resources

  • Resource 1 - These days I'm learning the JavaScript stuff from Jonas's course. One of the new things I've learned is how to use "use strict" mode. It's basically used at the top of the script and it works the "modern way".
  • Resource 2 - This is a great video which helped me understand how to use fetch() nethod.

Author

advice-generator-app's People

Contributors

doileo avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.