Giter VIP home page Giter VIP logo

javascript3's People

Contributors

arasmr avatar

Watchers

 avatar

javascript3's Issues

Well done!

Hello Emre,

The code works just fine, and it seems you got the logic behind the exercise. Only one comment, it is advisable to use 'use strict' in each JS file.

Wish you all the best!

Feedback Homework JS3 Week 1

Hi Emre, here is my feedback on your homework.

  1. Your eslintrc.json file gave me a warning in VSCode. For some reason you have copied the same object (each one starting with "env": {) multiple times. It should only be there once.
  2. Your getAverageRating() method should compute the average of all ratings added with addRating(). At present is just returns the ratings array, not the average.
  3. Your getAge() method returns the birth date, not the age. You must compute the age based on the current date and the person's birth date.
  4. In the assignment it was asked to get the director's name like this: director.getName(). This hints that the director was supposed to be a StaffMember object rather than just a string.

First feedback for week2 --

Well done Emre, but I notice that your first button doesn't work, could you revise your code and fixed it.
Cheers!

Feedback final homework

Hi Emre, here is my feedback on your homework. Overall your homework looks fine and I would not hesitate offering you an internship or job on the basis of this work. So, well done!

From a functionality point of view, one improvement would be useful: you need to clear out the innerHTML of the container when you make a new query. Otherwise the new results will just be appended to the previous results. So the first statement in the function bodies of repositoryClick and userClick could be:

container.innerHTML = '';

I'll now go through the individual criteria that I defined for this assignment:

  1. Your code must run without errors.

    Requirement is met.

  2. Your web page must be fit-for-purpose and well-designed. Place yourself in the role of an end-user: is the web page attractive and useful, or will you quickly click away?

    Requirement is met (but see the point about clearing previous results before rendering the new results).

    Your web page styling looks good too, but reviewing the CSS is not my expertise.

  3. Your code must be well-formatted.

    There are some minor formatting imperfections:

    • line 50, 81, 83: there should be a space before the = sign
    • line 58: there should be a space before "<hr>"
  4. Your repo must contain an .eslintrc.json file. There should be no avoidable ESLint warnings in your code. If you can fix the warning, do so. Please be prepared to account for any remaining warnings.

    ESLint flagged several missing semicolons (lines 1, 66, 67, 88, and 101)

  5. There should be no spelling errors in variable and function names, text strings and comments. If the VSCode spelling checker flags certain words as incorrect (and sometimes that is inevitable) you should be able to explain why that is. If you are uncertain about some word, consult an English dictionary.

    Requirement is met.

  6. Variable and function names must conform to these naming conventions.

    Requirement is met.

  7. Consider blank lines to convey a meaning, similar to using blank lines to separate paragraphs in a piece of written text. A blank line between function/method definitions is fine. A blank line that breaks up a piece of code that actually belongs together is wrong. Whenever you add a blank line, carefully consider whether the blank line helps or hurts readability. Keep it in only if it helps.

    Requirement is met.

  8. There should be no commented out code in your final homework. (Just like you wouldn't leave crossed out text in your CV).

    Requirement is met.

  9. There should be no unnecessary console.log statements in your final code. These statements are fine when developing and debugging, but not in your final product (and, as per point 8 above, don't just comment them out).

    Requirement is met.

  10. Review your own code as if you were an employer yourself. Would you offer yourself an internship or job when running and looking at the code?

    I would say: yes.

There are still some improvements that I would make to the code, to further enhance readability. You can use functions to further carve up your code into smaller chunks (each of which does one particular task) and use parameters rather than global variables.

Another improvement is to chain the .then methods of the promises. A .then method can return a new promise so that you can chain another .then.

Below is the code that I modified from your version, using these principles:

"use strict";
{
  //  API Links to Fetch

  const repLink = "https://api.github.com/repos/HackYourFuture/";
  const userLink = "https://api.github.com/users/";

  // Linked With The Html

  function render() {
    const root = document.getElementById("root");

    const header = createAndAppend("div", root);
    header.setAttribute("id", "header");

    const container = createAndAppend("div", root);
    container.setAttribute("id", "container");

    const gitLogo = createAndAppend("img", header);
    gitLogo.setAttribute("src", "images/github.png");
    gitLogo.setAttribute("class", "logo");

    const hyfLogo = createAndAppend("img", header);
    hyfLogo.setAttribute("src", "images/logo.png");
    hyfLogo.setAttribute("class", "logo");

    const input = createAndAppend("input", header);
    input.setAttribute("placeholder", "Type User Name or Repository Name");
    input.setAttribute("type", "text");

    const button = createAndAppend("button", header, "Search Hack Your Future Repository");
    button.addEventListener("click", () => repositoryClick(container, input));

    const button1 = createAndAppend("button", header, "Search User Repositories");
    button1.addEventListener("click", () => userClick(container, input));
  }

  // Render Repository Button Click

  function repositoryClick(container, input) {
    container.innerHTML = '';
    const repUrl = repLink + input.value;
    getJson(repUrl)
      .then(repoData => {
        renderRepoData(repoData, container);
        return getJson(repoData.contributors_url);
      })
      .then(contributors => {
        renderContributors(contributors, container);
      })
      .catch(error => console.error(error.message));
  }

  function renderRepoData(repoData, container) {
    const repositoryName = createAndAppend("h1", container, repoData.full_name);
    repositoryName.setAttribute("id", "repositoryName");

    const repositoryUrl = createAndAppend("a", container, "Link Of Repository: " + repoData.html_url);
    repositoryUrl.setAttribute("id", "repositoryUrl");
    repositoryUrl.setAttribute("href", repoData.html_url);
    repositoryUrl.setAttribute("target", "_blank");

    const contributor = createAndAppend("h2", container, "Contributors");
    contributor.setAttribute("id", "contributors");
  }

  function renderContributors(contributors, container) {
    const contributorsList = createAndAppend("ul", container);
    contributorsList.setAttribute("id", "contributorListLi");

    for (const contributor of contributors) {
      const li = createAndAppend("li", contributorsList);

      const a = createAndAppend("a", li, "<hr>" + "User Name: " + contributor.login + "<br><br>");
      a.setAttribute("href", contributor.html_url);
      a.setAttribute("target", "_blank");
      a.setAttribute("id", "userLoginLink");

      const userAvatar = createAndAppend("img", li);
      userAvatar.setAttribute("src", contributor.avatar_url + "<hr>");
      userAvatar.setAttribute("id", "userAvatar");
    }
  }

  function userClick(container, input) {
    container.innerHTML = '';
    const userUrl = userLink + input.value + "/repos";
    getJson(userUrl)
      .then(userData => {
        renderUserData(userData, container);
      })
      .catch(error => console.error(error.message));
  }

  function renderUserData(userData, container) {
    const userLogo = createAndAppend("img", container);
    userLogo.setAttribute("src", userData[0].owner.avatar_url);
    userLogo.setAttribute("id", "userLogo");

    const userName = createAndAppend("h2", container, userData[0].owner.login);
    userName.setAttribute("id", "userName");

    for (const userItem of userData) {
      const reposName = createAndAppend("h2", container, userItem.name);
      reposName.setAttribute("id", "reposName");

      const reposLink = createAndAppend("a", container, userItem.html_url);
      reposLink.setAttribute("href", userItem.html_url);
      reposLink.setAttribute("target", "_blank");
      reposLink.setAttribute("id", "reposLink");
    }
  }

  // XMLHttpRequest to Fetch Json File

  function getJson(url) {
    return new Promise((resolve, reject) => {
      const xhr = new XMLHttpRequest();
      xhr.open("GET", url);
      xhr.responseType = "json";
      xhr.send();
      xhr.onload = () => resolve(xhr.response);
      xhr.onerror = () => reject(new Error(xhr.statusText));
    });
  }

  // Create and Append Function for DRY(do not repeat yourself)

  function createAndAppend(name, append, innerHTML) {
    const child = document.createElement(name);
    append.appendChild(child);
    if (innerHTML !== undefined) {
      child.innerHTML = innerHTML;
    }
    return child;
  }

  render();
}

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.