Coder Social home page Coder Social logo

advice-generator'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.

Table of contents

Overview

The challenge

Users should be able to:

  • click on the dice button on the bottom of the screen and a quote will populate in the box.

Screenshot

Links

My process

Built with

  • Semantic HTML5 markup
  • CSS custom properties
  • Flexbox
  • Mobile-first workflow
  • Javascript

What I learned

I learned you have to set the width of the paragraph element to a specific px. Or when you generate the quote the added space will mess up css. Also, you can set flexbox on the body to make sure everything is either in rows or columns to your specifications with out alot of guess work. Also, i used Axios (npm) for the api fetch. I feel it works better for me, and javascript promises. it is a library that is good to work with and get familar with for client side node.js work.

This code centers the container, and makes sure the elements are stacked.

body {
  background-color: hsl(218, 23%, 16%);
  font-family: 'Manrope';
  font-size: 18px;
  height: 94vh;
  display: flex;
  flex-direction: column;
}

This Css below sets up the quote body and sets a width on the quote body to stay put and not expand.

#quote {
  font-weight: 800;
  margin: 0;
  text-align: center;
  width: 295px;
}

This is the axios code that i used to pull the api request. I like it becuase it is short and sweet,and not alot of lines of code.

const digit = document.getElementById('digits');
const quote = document.getElementById('quote');
const generate = document.querySelector('.btn');
const adviceQuote = async () => {
  const res = await axios.get('https://api.adviceslip.com/advice');
  try {
    digit.textContent = res.data.slip.id;
    quote.textContent = `"${res.data.slip.advice}"`;
  } catch (e) {
    console.log('error', e);
  }
};
generate.addEventListener('click', adviceQuote);

Continued development

Plans i have are to add a background changer, and a pop up greeting name and date.

Useful resources

  • MDN - This is a great source for people starting out. Also, helps with looking up solutions and reworking your code.

Author

advice-generator's People

Contributors

marjeanm avatar

Watchers

James Cloos avatar  avatar

Forkers

yn56yyh

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.