Code Monkey home page Code Monkey logo

exercise-conditional-profile-card's Introduction

Conditional Profile Card

Note: If you are working locally, make sure that you have node.js installed in your computer by typing in your terminal:

$ node -v

๐ŸŒฑ How to start this project

This project comes with the necessary files to start working immediately.

We recommend opening this very same repository using a provisioning tool like Codespaces (recommended) or Gitpod. Alternatively, you can clone it on your local computer using the git clone command.

This is the repository you need to open:

https://github.com/breatheco-de/exercise-conditional-profile-card.git

๐Ÿ‘‰ Please follow these steps on how to start a coding project.

To see the result in the browser, you will need to start the project by running the following command in your terminal:

$ npm run start

๐Ÿ’ก Important: Remember to save and upload your code to GitHub by creating a new repository, updating the remote (git remote set-url origin <your new url>), and uploading the code to your new repository using the add, commit and push commands from the git terminal.

Some context

As a web developer, you will be creating lots and lots of dynamic HTML using JavaScript based algorithms.

In this exercise, you have to create the HTML code needed to render a profile card based on a series of variables that could change in value during runtime. Here is an example of the profile card:

Conditional Profile Card

Inside the src/app.js file there is a render function that receives variables and contains the logic to create most of the website HTML code.

function render(variables = {}) {
  document.querySelector("#widget_content").innerHTML = `<div>Website code</div>`;
}

You can see the variables that are being generated by typing on the developer console:

console.log(window.variables);
/*
{
    includeCover: true, // if includeCover is true the algorithm should show the cover image
    background: "https://images.unsplash.com/photo-1511974035430-5de47d3b95da", // this is the image's url that will be used as a background for the profile cover
    avatarURL: "https://randomuser.me/api/portraits/women/42.jpg", // this is the url for the profile avatar
    socialMediaPosition: "left", // social media bar position (left or right)
    
    twitter: null, // social media usernames
    github: "alesanchezr",
    linkedin: null,
    instagram: null,

    name: null,
    lastName: null,
    role: null,
    country: null,
    city: null
}
*/

๐Ÿ“ Instructions

These instructions come with a video for better understanding: https://youtu.be/gaVm8eyCqlM

  1. Read and understand the render function and the value of the variables variable that it receives.

  2. Change the content of the render function to make it render the variables on the card.

๐Ÿ’ก Attention!

You do not need to add any event listeners to the elements that are already built in the project. This is already being done by this part of the code:

document.querySelectorAll(".picker").forEach(function(elm) {
    elm.addEventListener("change", function(e) {
      // <- add a listener to every input
      const attribute = e.target.getAttribute("for"); // when any input changes, collect the value
      let values = {};
      values[attribute] =
        this.value == "" || this.value == "null"
          ? null
          : this.value == "true"
          ? true
          : this.value == "false"
          ? false
          : this.value;
      render(Object.assign(window.variables, values)); // render again the card with new values
    });
  });

So when the elements contents "change" they will already update the variable values for each element. All you need to do is to update the HTML content inside render function, as mentioned on instruction 1.

Initial Variable Values

Name Type Default Value Description
includeCover boolean true it determines if the cover shoud be visible with an image or not
background string null the image's url that will be used as a background for the profile cover
avatarURL string null the url for the profile avatar
socialMediaPosition string "right" it can be left or right and it determines where to place the social media bar
twitter string null the twitter username to be displayed on the profile
github string null the github username to be displayed on the profile
linkedin string null the linkedin username to be displayed on the profile
instagram string null the instagram username to be displayed on the profile
name string null The name of the user to be displayed on the profile
lastName string null The name of the user to be displayed on the profile
role string null The name of the user to be displayed on the profile
country string null The name of the user to be displayed on the profile
city string null the city of the user to be displayed on the profile

Hard-Coded HTML

This is an example of a possible HTML output, you will have to replace the name, last name, etc. With the values that these variables may have.

<div class="widget">
  <div class="cover"><img src="https://the_url.com/for_the_background.png" /></div>
  <img src="https://the_url.com/for_the_image.png" class="photo" />
  <h1>Ryan Boylett</h1>
  <h2>Web Developer</h2>
  <h3>Miami, USA</h3>
  <ul class="position-right">
    <li><a href="https://twitter.com/alesanchezr"><i class="fa fa-twitter"></i></a></li>
    <li><a href="https://github.com/alesanchezr"><i class="fa fa-github"></i></a></li>
    <li><a href="https://linkedin.com/alesanchezr"><i class="fa fa-linkedin"></i></a></li>
    <li><a href="https://instagram.com/alesanchezr"><i class="fa fa-instagram"></i></a></li>
  </ul>
</div>

This and many other projects are built by students as part of the 4Geeks Academy Coding Bootcamp by Alejandro Sanchez and many other contributors. Find out more about our Full Stack Developer Course, and Data Science Bootcamp.

exercise-conditional-profile-card's People

Contributors

alesanchezr avatar dependabot[bot] avatar elviraqdp avatar javilomark avatar jferragut avatar jimenaeb avatar joancastillo avatar jonagarces avatar josemoracard avatar juanantonaccio avatar kant avatar leomuzicarvalho avatar lorenagubaira avatar marcogonzalo avatar mortegac avatar mrmandujano avatar samu1243 avatar tommygonzaleza avatar vlmarq avatar zerkley avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

exercise-conditional-profile-card's Issues

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.