Giter Site home page Giter Site logo

js-data-types-training's Introduction

Training: JavaScript Data Types

Use the JavaScript console in your browser to solve the challenges. Press command + option + J to open the console in Chrome. Feel free to also record your responses in a file, but make sure you test them in the console!

Strings

  1. Store your first name in a variable.
  2. Concatenate your first name with your last name, and store the result in another variable.
  3. Use the String split method to turn your string variable from challenge #2 into an array.

Arrays

  1. An array called foods holds the names of my top 20 favorite foods, starting with the best food. How can you find my fifth favorite food?
answer ```js foods[4] ```
  1. Starting from the existing friends variable below, change the element that is currently "Elizabeth" to "Liz".
var friends = [
  "Moe",
  "Jane",
  "Emma",
  "Elizabeth",
  "Abanov",
  "Lycia"
];
answer ```js friends[3] = "Liz"; ```
  1. Using array methods, add your name to the end of the friends array, and add another name to beginning.
hint Look up array methods `push` and `unshift`.
answer ```js friends.push("Me!"); friends.unshift("Someone else!"); ```
  1. We have two lists of friends below. Use array methods to combine them into one alphabetically-sorted list.
var myFriends = [
  "Rickon",
  "Meera",
  "Hodor",
  "Jojen",
  "Osha",
  "Rickard",
  "Maester"
];

var yourFriends = [
  "Bilbo",
  "Boromir",
  "Elrond",
  "Faramir",
  "Frodo",
  "Gandalf",
  "Legolas",
  "Pippin"
];
hint Look up array methods `concat` and `sort`.
answer ```js var allFriends = myFriends.concat(yourFriends); allFriends.sort(); ```
  1. This array contains 2 arrays, of different groups of friends. But everyone became friends! Merge these two arrays into a single array using array methods.
var friends = [
  [
    "George",
    "John",
    "Ringo",
    "Paul"
  ], [
    "Brian",
    "Mick",
    "Keith",
    "Ian",
    "Bill",
    "Charlie"
  ]
]
answer ```js friends[0].concat(friends[1]); ```

Strings & Arrays

  1. We have an array of the cardinal directions. In one line, get the first letter of the word "north" from this array.
var directions = [
"north",
"south",
"east",
"west"
];
answer ```js directions[0][0]; ```
  1. We need to use in-between directions, like "east northeast", when navigating. Build the string "east northeast" using this array.
answer ```js directions[2] + " " + directions[0] + directions[2]; ```
  1. We can shorten east northeast into shorthand using just the first letters, ene. Build that string using this array.
answer ```js directions[2][0] + directions[0][0] + directions[2][0]; ```

js-data-types-training's People

Contributors

mnfmnfm avatar bgveenstra avatar

Watchers

James Cloos avatar  avatar

Forkers

arielajaneen

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.