Coder Social home page Coder Social logo

meet-mr-fox-json-to-html's Introduction

Meet Mr. Fox -- JSON to HTML Challenge

Your goal is to fill in the blanks in Mr. Fox's profile using jQuery, and data from a JSON object.

Setup

Please clone this repo.

Open index.html in your browser, and launch your Chrome Javascript Console.

You will be coding in the files scripts/app.js and index.html.

Please note that the JSON object is accessible by typing data. Each time you refresh it will change a little bit (just to keep you on your toes!).

Pre-Requisite Skills

  • Getting Values from Objects and Arrays
    • Using Bracket Notation
    • Using Dot Notation
  • Looping over Arrays/Lists
    • Using the current index of the loop
  • Combining Strings using Concatination
    • Creating HTML strings

Looping Lists

Often we want to do this same thing multiple times, but with values at different indexes.

var list = ["a", "b", "c"];
for(var i=0; i<list.length; i++){
  console.log(i, list[i]);
}
// 0 a
// 1 b
// 2 c

We can do the same thing with the powerful forEach Array method:

var list = ["a", "b", "c"];
list.forEach(function(value, i){
    console.log(i, value);
})
// 0 a
// 1 b
// 2 c

What is JSON?

JSON is a convenient format for transferring data. It is supported in many languages, not just Javascript!

Although Javascript Objects and JSON have a lot in common, JSON follows a slightly more strict format.

Here is an example of a JSON object:

{
    "key": "value"
}

We can assign the object to a variable o.

var o = {
    "key": "value",
    list: ["a", "b", "c"]
}

To access values, we need to know the name of the key. We can use either dot notation or bracket notation:

// dot notation
o.key;      //=> "value"

// bracket notation
o["key"];   //=> "value"
o['key'];   //=> "value"

Sometimes you'll need to "drill" down into an object to get the value you want.

**How would you get the value `"c"`?** (Click Here)
```js o.list[2]; // "c" o.["list"][2]; // "c" o.['list'][2]; // "c" o.['list']['2']; // "c" o.['list']["2"]; // "c" ```

But note that o.list.2 will never work. Why is that?

What is Concatination?

When we combine strings together, it's known as "concatination". Here's an example:

"1" + "1";                  //=> "11"
"what's" + "up?";           //=> "what'sup?"
"hello" + " " + "world";    //=> "hello world"
**""What'll happen when you "quote" a quote?", he asked, helplessly"** (Click Here)
```js 'this "works"' "and this'll work" 'but don't do this!' // SyntaxError "He said \"don't\" do this, but I'm clever" // escape inner quotes with forward slash ```

We can create HTML strings by simpling creating a string containing HTML:

var p = "<p>simple paragraph</p>";

var words = "words words words";
var dynamic_paragraph = (
    "<p>" +
        words + "!" +
    "</p>"
);

dynamic_paragraph //=> "<p>words words words!</p>"

meet-mr-fox-json-to-html's People

Contributors

nathanallen avatar

Watchers

James Cloos avatar David Kim 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.