Giter Club home page Giter Club logo

js-data-types's Introduction

Javascript Data Types Exercises

Instructions

  1. Clone this repo: $ git clone [email protected]:ga-wdi-exercises/js-data-types.git
  2. Follow the instructions to each section in exercise.md. All the questions will have you provide an answer in a dedicated space below each of them.

How To Test Your Code

Open index.html in your browser.

  • If you just want to a line or two of code, you can enter and run it directly in the browser Javascript console as a REPL.
  • If you want to run a longer block of code (e.g., a loop or series of conditionals), type it out in script.js and use console.log statements to see the result in the browser Javascript console.

js-data-types's People

Contributors

amaseda avatar robertakarobin avatar superbuggy avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

js-data-types's Issues

Js Basics HW

comfort_level: 4
completeness: 5

// What is the return value of the below code sample? Provide a sentence or two of explanation.
typeof( 15 ); //This would return as 'number' because 'typeof' tests for variable type and '15' is a number.

// What is the return value of the below code sample? Provide a sentence or two of explanation.
typeof( "hello" ); //This would return as 'string' because typeof tests for variable type and "hello" is a string.

// What is the return value of the below code sample? Provide a sentence or two of explanation.
typeof( [ "dog", "cat", "horse" ] ); //This would return an object because this collection of strings is a composite variable type, and 'typeof' checks for variable type.

// What is the return value of the below code sample? Provide a sentence or two of explanation.
typeof( NaN ); //This would return as a number because 'NaN' is an irrational number that can't be written conclusively with finite numbers, but it's still classified as a number variable type, and 'typeof' checks for variable type.

// What is the return value of the below code sample? Provide a sentence or two of explanation.
"hamburger" + "s"; //This would yield "hamburgers" because '+' when used with strings is treated as a concatenator.

// What is the return value of the below code sample? Provide a sentence or two of explanation.
"hamburgers" - "s"; //This would yield 'NaN' because '-' is a mathematical operator for subtracting numbers, and both of these variables are strings.

// What is the return value of the below code sample? Provide a sentence or two of explanation.
"johnny" + 5; //This would yield "johnny5" because '+' when used with strings is treated as a concatenator, so '5' is parsed to string "5" and concatenated.

// What is the return value of the below code sample? Provide a sentence or two of explanation.
99 * "luftbaloons"; //This would yield 'NaN' because '*' is a mathematical operator for multiplying numbers, and both of these variables aren't numbers.

// What will the contents of the below array be after the below code sample is executed.
var numbers = [ 2, 4, 6, 8 ];
numbers.pop(); // [ 2, 4, 6]
numbers.push( 10 ); //[2, 4, 6, 10]
numbers.unshift( 3 ); //[3, 2, 4, 6, 10] and it would return the new length of '5'

// What is the return value of the below code sample?
var morse = [ "dot", "pause", "dot" ]; //Creates array morse with these three strings.
var moreMorse = morse.join( " dash " ); //Creates string "dot dash pause dash dot"
moreMorse.split( " " ); //This would create an object containing seperate entities split by every " ".

// What will the contents of the below array be after the below code sample is executed.
var bands = []; //Creates array 'bands'.
var beatles = [ "Paul", "John", "George", "Pete" ]; //Creates array beatles with the four listed strings.
var stones = [ "Brian", "Mick", "Keith", "Ronnie", "Charlie" ]; //creates array stones with the five listed strings.
bands.push( beatles ); //Pushes array 'beatles' onto the end of 'bands' which is initially empty, so it ends up being the same as 'beatles'.
bands.unshift( stones ); // Adds the stones array to the front of the bands array, which now contains both arrays: [["Brian", "Mick", "Keith", "Ronnie", "Charlie"]["Paul", "John", "George", "Pete"]]
bands[ bands.length - 1 ].pop(); //Yields the end string in bands, which is being 'popped' off because it's index = bands.length-1 : [["Brian", "Mick", "Keith", "Ronnie", "Charlie"]["Paul", "John", "George"]]
bands[0].shift(); //Yields the first string in bands, which is being removed via 'shift', leaving bands array as : [["Mick", "Keith", "Ronnie", "Charlie"]["Paul", "John", "George"]]
bands[1][3] = "Ringo"; //Yields the string "Ringo", and adds the string into the 2nd array (array of index 1) at index position 3, which is the end: [["Mick", "Keith", "Ronnie", "Charlie"]["Paul", "John", "George", "Ringo"]]

JS basics

completeness: 3.5
comfort:4

Had to call it a night. Need Sleep.

JS Basics HW Answers

comfort_level: 3
completeness: 5

// What is the return value of the below code sample? Provide a sentence or two of explanation.
typeof( 15 );

number
15 is a number.

// What is the return value of the below code sample? Provide a sentence or two of explanation.
typeof( "hello" );
string
the word hello is in quotes, and therefore is a string.
// What is the return value of the below code sample? Provide a sentence or two of explanation.
typeof( [ "dog", "cat", "horse" ] );

string
all three are strings

// What is the return value of the below code sample? Provide a sentence or two of explanation.
typeof( NaN );

undefined
NaN is neither a string, number, or boolean

// What is the return value of the below code sample? Provide a sentence or two of explanation.
"hamburger" + "s";

hamburgers
string + string causes js to recognize as cat

// What is the return value of the below code sample? Provide a sentence or two of explanation.
"hamburgers" - "s";

NaN
two strings are being subtracted, but the subtraction operations causes js to expect two numbers

// What is the return value of the below code sample? Provide a sentence or two of explanation.
"johnny" + 5;

johnny5
string + number causes cat

// What is the return value of the below code sample? Provide a sentence or two of explanation.
99 * "luftbaloons";

NaN
strings can not be multiplied by numbers

// What will the contents of the below array be after the below code sample is executed.
var numbers = [ 2, 4, 6, 8 ];
numbers.pop();
numbers.push( 10 );
numbers.unshift( 3 );

[ 3, 4, 6, 10 ];
.pop causes a removal of the last numer in the array
.push( 10 ) causes an addition of the number 10 to the end of the array
.unshift( 3 ) causes an addition of the number 3 to the front of the array

// What is the return value of the below code sample?
var morse = [ "dot", "pause", "dot" ];
var moreMorse = morse.join( " dash " );
moreMorse.split( " " );

answer before attempting "dotpausedotdash"
i thought join converted all elements of array into a string, and split removed the space between quotes

answer after attempting [ 'dot', 'dash', 'pause', 'dash', 'dot' ]
i re-checked the definition of split... so what i think happened is, split removed the spaces between quotes and then output a new array

// What will the contents of the below array be after the below code sample is executed.
var bands = [];
var beatles = [ "Paul", "John", "George", "Pete" ];
var stones = [ "Brian", "Mick", "Keith", "Ronnie", "Charlie" ];
bands.push( beatles );
bands.unshift( stones );
bands[ bands.length - 1 ].pop();
bands[0].shift();
bands[1][3] = "Ringo";

bands = [[ "Paul", "John", "George", "Pete" ]];
push adds contents of beatles to array

bands = [[ "Brian", "Mick", "Keith", "Ronnie", "Charlie" ], [ "Paul", "John", "George", "Pete" ]];
unshift adds contents of stones to front of array

bands = [[ "Brian", "Mick", "Keith", "Ronnie", "Charlie" ], [ "Paul", "John", "George" ]];
.length - 1 finds the length of the array (9) and subtracts it by 1, which equals 8. pop removes the eighth value of the array

"Brian"
.shift removed "Brian" from the array and returned the string "Brian"

[["Mick", "Keith", "Ronnie", "Charlie" ], [ "Paul", "John", "George", "Ringo" ]];
bands[1][3] = "Ringo" adds "Ringo" to the fourth [3] position of the second [1] array

JS basics HW

comfort:4
completeness: 3
Had to call it a night.

Basics HW

Comfort: 4
Completeness: 5

// What is the return value of the below code sample? Provide a sentence or two of explanation.
typeof( 15 );
--Numbers; The function returns the type of code that was written
// What is the return value of the below code sample? Provide a sentence or two of explanation.
typeof( "hello" );
--String; The function reads the letters in the code, declaring it a string

// What is the return value of the below code sample? Provide a sentence or two of explanation.
typeof( [ "dog", "cat", "horse" ] );
--String; The function reads the letters in the code and declares it as a string form

// What is the return value of the below code sample? Provide a sentence or two of explanation.
typeof( NaN );
--NaN; The value NaN declares that it's not a number, because it's not in parenthesis it recognizes it in that same form

// What is the return value of the below code sample? Provide a sentence or two of explanation.
"hamburger" + "s";
--"hamburgers" the string is put together with addition

// What is the return value of the below code sample? Provide a sentence or two of explanation.
"hamburgers" - "s";
--"hamburger"; the string loses its "s" after the (-) operator

// What is the return value of the below code sample? Provide a sentence or two of explanation.
"johnny" + 5;
--johnny5; The string is recognized and places the 5 at the end of johnny to follow the rule

// What is the return value of the below code sample? Provide a sentence or two of explanation.
99 * "luftbaloons";
--NaN; these two types of data can't be multiplied because luftbaloons is a string and not a number

// What will the contents of the below array be after the below code sample is executed.
var numbers = [ 2, 4, 6, 8 ];
numbers.pop(); [2, 4, 6]
numbers.push( 10 ); [2, 4, 6, 10]
numbers.unshift( 3 ); [3, 2, 4, 6, 10]

// What is the return value of the below code sample?
var morse = [ "dot", "pause", "dot" ];
var moreMorse = morse.join( " dash " ); "dot pause dot dash"
moreMorse.split( " " );[dot, pause, dot, dash]

// What will the contents of the below array be after the below code sample is executed.
var bands = [];
var beatles = [ "Paul", "John", "George", "Pete" ];
var stones = [ "Brian", "Mick", "Keith", "Ronnie", "Charlie" ];

bands.push( beatles );[ "Paul", "John", "George", "Pete" ];

bands.unshift(stones); [ "Brian", "Mick", "Keith", "Ronnie", "Charlie" ]["Paul", "John", "George", "Pete" ];
bands.length -[ 1 ].pop(); [ "Brian", "Mick", "Keith", "Ronnie", "Charlie" ]["Paul", "John", "Pete" ];
bands[0].shift(); ["Mick", "Keith", "Ronnie", "Charlie" ]["Paul", "John", "Pete" ];
bands[1][3] = "Ringo";["Mick", "Keith", "Ronnie", "Charlie" ]["Paul", "John", "Ringo" ];

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.