r/javaScriptStudyGroup • • Nov 06 '17

Help with Star Wars api and js

2 Upvotes

Hi,

Hope everyone is doing great :)

I am quite rusty with js and wanted to practise by pulling data from the star wars api and dynamically inserting it into divs. Specifically I am pulling planet information, using the key values to populate the " table" header(i am using css display:table). The rows of the table should be each planet + information(limited to 7 items). The script below seems to do this for the first planet but cant for the life of me figure out how to make it go through each planet and do that. Obviously feel free to laugh/mock/kudos/criticize my code, it would help me loads.

Any ideas?

Thanks everyone!

const fetchPlanets  = fetch('https://swapi.co/api/planets/');
getPlanets();
function getPlanets(){
fetchPlanets.then(
    (data) => data.json()
)
.then(
    (planetList)=> {
        let planetItems = planetList.results;
        console.log(planetItems);
        for (var i = 0; i < planetItems.length; i++) {       
            let planets = document.getElementById("planets"); 
            let tableHeader = document.getElementById("table-header"); 
            let tableRow = document.createElement("div");
            planets.setAttribute("class", "table");
            tableHeader.setAttribute("class", "table-header");
            tableRow.setAttribute("class", "table-row");
            let keyTitles = Object.keys(planetItems[0]);       
            for (var i =0; i <  keyTitles.length; i++){
                if(i < 7) {
                    let tableCellHeader = document.createElement("div");
                    let tableCell = document.createElement("div");
                    let planetData = Object.values(planetItems[i]);
                    tableCellHeader.setAttribute("class", "table-cell");
                    tableCellHeader.innerHTML = keyTitles[i].replace("_", " ");
                    tableHeader.appendChild(tableCellHeader);
                    //planetData rows
                    planets.appendChild(tableRow);
                    tableRow.appendChild(tableCell);
                    tableCell.setAttribute("class", "table-cell");
                    tableCell.innerHTML = planetData[i]; 
                }  
           }     
      }
    }
  )  

}

r/javaScriptStudyGroup • • Oct 08 '17

I created a memorable password generator - critique and suggest improvements! :)

Thumbnail pswrd.co
2 Upvotes

r/javaScriptStudyGroup • • Sep 27 '17

Why is !=== not valid JS?

2 Upvotes

I have always seen !== and never !===.


r/javaScriptStudyGroup • • Sep 24 '17

A guide to parallel programming in JavaScript

Thumbnail
madhugnadig.com
2 Upvotes

r/javaScriptStudyGroup • • Sep 03 '17

ISO: JavaScript Mentor

2 Upvotes

Or at least someone who can help me understand my homework assignments. Currently Junior at ASU Online taking a beginning JS class. Text book is Murach JavaScript 2nd edition. If this isn't the right reddit to look for help I would appreciate being pointed in the right direction! Thanks.

Also, new to reddit, so be gentle. Thx.


r/javaScriptStudyGroup • • Oct 24 '16

REST service authentication using jsonwebtoken

Thumbnail
jsdebugger.com
2 Upvotes

r/javaScriptStudyGroup • • May 15 '16

Check out my latest CodPen!

Thumbnail
codepen.io
2 Upvotes

r/javaScriptStudyGroup • • May 10 '16

CHALLENGE: Write a multiplication function...

2 Upvotes

CHALLENGE:

Write a multiplication function that takes two numbers integers as arguments and returns their product.

Rules:

  1. Cannot use * or / operators

  2. Cannot use Math object

  3. Cannot use for (any variation) or while (including do) loops


r/javaScriptStudyGroup • • Apr 25 '16

[Week 15] Focus: Programming Challenges (cont.)

2 Upvotes

So here we are at Week 15. Week 15's focus will be programming challenges (continued from last week).

Here is a link to the object oriented challenges:

http://www.w3resource.com/javascript-exercises/javascript-object-exercises.php

It will work like this:

  • Monday: Announce focus (eg, programming challenges (cont.))

  • Build throughout the week... Two rules: 1) must use javascript 2) must provide a solution or work done on at least one of the challenges listed above.

  • Friday: Post demos/projects in this thread (can begin reviewing immediately); first line of an entry should be ENTRY and it should be a top level comment (ie, don't put your entry in a reply)

  • Sat and Sun: Review projects/figure out focus for next week

GENERAL GUIDELINES FOR FEEDBACK:

  • Be nice!! ALL KNOWLEDGE/SKILL LEVELS ARE WELCOME AND ENCOURAGED TO PARTICIPATE.

  • If you don't want feedback, if it makes you uncomfortable or you're just not interested, simply say so... Others, please be respectful of this. Conversely, if you do want feedback, try to be specific on which aspects... even if you just say "all/everything.

But that's about it... Have fun! :) Feel free to ask questions and discuss throughout the week!


r/javaScriptStudyGroup • • Apr 12 '16

[Week 13] Focus: Object object

2 Upvotes

So here we are at Week 13. Week 13's focus will be javascript's Object object.

Background info: https://msdn.microsoft.com/library/kb6te8d3%28v=vs.94%29

It will work like this:

  • Monday: Announce focus (eg, Object object)

  • Build throughout the week... Two rules: 1) must use javascript 2) must use at least 1 direct example of JavaScript's Object object.

  • Friday: Post demos/projects in this thread (can begin reviewing immediately); first line of an entry should be ENTRY and it should be a top level comment (ie, don't put your entry in a reply)

  • Sat and Sun: Review projects/figure out focus for next week

GENERAL GUIDELINES FOR FEEDBACK:

  • Be nice!! ALL KNOWLEDGE/SKILL LEVELS ARE WELCOME AND ENCOURAGED TO PARTICIPATE.

  • If you don't want feedback, if it makes you uncomfortable or you're just not interested, simply say so... Others, please be respectful of this. Conversely, if you do want feedback, try to be specific on which aspects... even if you just say "all/everything.

But that's about it... Have fun! :) Feel free to ask questions and discuss throughout the week!


r/javaScriptStudyGroup • • Apr 10 '16

Midas Gold Plus - bear with me

2 Upvotes

So for the last 2 months I've become hooked on Midas Gold Plus; an idle game on Kongregate.
Midas Gold Plus

This is relevant because I've become known in the community because I made them a skill calculator for part of the game that I've since expanded on several times. The game creators even gave me like $20 of premium currency in recognition :)

Left it on codepen where it has had almost 4k views.
Some of it clearly only makes sense if you dig into the game but leaving it here because, as always, I would welcome any sort of feedback etc. It qualifies as my most relevant / used / purposeful thing I've made and actually got out there :)
Skill Calculator


r/javaScriptStudyGroup • • Mar 21 '16

[Week 10] Focus: apply(), call(), bind()

2 Upvotes

So here we are at Week 10. Week 10's focus will be apply(), call(), bind().

Background info (lengthy, but touches on all three): http://javascriptissexy.com/javascript-apply-call-and-bind-methods-are-essential-for-javascript-professionals/

It will work like this:

  • Monday: Announce focus (eg, apply(), call(), bind())

  • Build throughout the week... Two rules: 1) must use javascript 2) must use at least 1 example each of apply(), call(), bind().

  • Friday: Post demos/projects in this thread (can begin reviewing immediately); first line of an entry should be ENTRY and it should be a top level comment (ie, don't put your entry in a reply)

  • Sat and Sun: Review projects/figure out focus for next week

GENERAL GUIDELINES FOR FEEDBACK:

  • Be nice!! ALL KNOWLEDGE/SKILL LEVELS ARE WELCOME AND ENCOURAGED TO PARTICIPATE.

  • If you don't want feedback, if it makes you uncomfortable or you're just not interested, simply say so... Others, please be respectful of this. Conversely, if you do want feedback, try to be specific on which aspects... even if you just say "all/everything.

But that's about it... Have fun! :) Feel free to ask questions and discuss throughout the week!


r/javaScriptStudyGroup • • Mar 07 '16

[Week 8] Focus: DOM Manipulation

2 Upvotes

So here we are at Week 8 (two months strong!! :)). Big THANK YOU!!! to all who participated in Week 7 (which can now be found over in the sidebar). Week 8's focus, as sourced from the participants of Week 7, will be DOM manipulation.

Background info on Document Object Model:

http://www.w3schools.com/jsref/dom_obj_document.asp

https://developer.mozilla.org/en-US/docs/Web/API/Document_Object_Model/Introduction

It will work like this:

  • Monday: Announce focus (eg, DOM manipulation)

  • Build throughout the week... Two rules: 1) must use javascript 2) must use at least 1 example of manipulating the DOM.

  • Friday: Post entries/demos/projects in this thread; first line of an entry should be ENTRY in bold, and it should be a top level comment (ie, don't put your entry in a reply)

  • Sat and Sun: Review projects/figure out focus for next week

GENERAL GUIDELINES FOR FEEDBACK:

  • Be nice!! ALL KNOWLEDGE/SKILL LEVELS ARE WELCOME AND ENCOURAGED TO PARTICIPATE.

  • If you don't want feedback, if it makes you uncomfortable or you're just not interested, simply say so... Others, please be respectful of this. Conversely, if you do want feedback, try to be specific on which aspects... even if you just say "all/everything; try to be somewhat specific if possible.

But that's about it... Have fun! Be creative... or not. :) Feel free to ask questions and discuss throughout the week!


r/javaScriptStudyGroup • • Feb 22 '16

Python 3 range in JS

2 Upvotes

Was reading through some posts over at ES6 Discuss and came across people asking for range style functions to be in next update of JS.

Decided to give making one a go. Managed to get it shorter than I thought I would.
Gives same results as Python 3. ie.

range(5) = 0, 1, 2, 3, 4
range(1, 5) = 1, 2, 3, 4  
range(0, 10, 2) = 0, 2, 4, 6, 8

For use with for..of iterators. Uses ES6 Generators / default params
Codepen


r/javaScriptStudyGroup • • Feb 01 '16

[Week 3] Focus: Recursion

2 Upvotes

Greetings!

So, here we are, Week 3. Not too much participation in Week 2, but that was expected. We'll keep pressing forward!!! Week 3's focus will bee recursion.

It will work like this:

  • Monday: Announce focus (eg, recursion)

  • Build throughout the week... 2 rules: 1) must use javascript 2) must use at least 1 example of recursion)

  • Friday: Post projects in this thread (can begin reviewing immediately); first line of an entry should be ENTRY and it should be a top level comment (ie, don't put your entry in a reply)

  • Sat and Sun: Review projects/vote on focus for next week

GENERAL GUIDELINES FOR FEEDBACK:

  • Be nice!!! ALL KNOWLEDGE/SKILL LEVELS ARE WELCOME AND ENCOURAGED TO PARTICIPATE.

  • If you don't want feedback, if it makes you uncomfortable or you're just not interested, then say so... Others, please be respectful of this. Conversely, if you do want feedback, try to be specific on which aspects... even if you just say "all/everything.

But that's about it... Have fun! :) Feel free to ask questions and discuss throughout the week!


r/javaScriptStudyGroup • • Jan 18 '16

[WEEK 1] Focus: Nested Loops

2 Upvotes

Greetings!

So, here we are, Week 1. We had some discussion (here) and it seems we've decided to go with nested loops as the focus of our first challenge.

It will work like this:

  • Monday: Announce focus (eg, nested loops)

  • Build throughout the week... 2 rules: 1) must use javascript 2) must use at least 1 nested loop (can be for, while, do while, etc)

  • Friday: Post projects in this thread (can begin reviewing immediately); first line of an entry should be ENTRY and it should be a top level comment (ie, don't put your entry in a reply)

  • Sat and Sun: Review projects/vote on focus for next week

GENERAL GUIDELINES FOR FEEDBACK:

  • Be nice!!! ALL KNOWLEDGE/SKILL LEVELS ARE WELCOME AND ENCOURAGED TO PARTICIPATE.

  • If you don't want feedback, if it makes you uncomfortable or you're just not interested, then say so... Others, please be respectful of this. Conversely, if you do want feedback, try to be specific on which aspects... even if you just say "all/everything.

But that's about it... Have fun! :) Feel free to ask questions and discuss throughout the week!

Link to a discussion that's already started: https://www.reddit.com/r/javaScriptStudyGroup/comments/41btv6/nested_loop_exercises/


r/javaScriptStudyGroup • • Jan 17 '16

Nested Loop Exercises

2 Upvotes

Each of these problems should have a height argument in the function. Ex.

makeTriangle(height);

Write programs to make each design in your console, and it should work for any height supplied to the function.

      1
     22
    333
   4444
  55555
 666666

   1
  222
 33333

//For this one, the input can be changed to an odd number (the next higher number)
     1
    22
   333
    44
     5