Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions basics.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,85 @@
/* Create a `myName` variable and assign it a String value */

function Person (name) {

var myName = name;
return myName;
}
console.log(Person('Gail'));


Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for a Person function.

/* Create a `person` variable and give it 2 properties,
* `name`, assign it the same name as before,
* as well as an `age` (number);
*/
var Person = {
name: 'Gail',
age: 21,
};


/* Create a function called `greet`,
* it should take a 1 parameter, `name`
* and it should print "Hello, my name is {name}"
*/
function greet (name) {
return "Hello, my name is " + name;

}
console.log(greet('Joe'));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

console.log is okay for testing locally. But please delete them before committing.

/* Create a variable called `canDrive`,
* if it should be true if your person object is at least 16 years old
*/
function canDrive (age) {

if (age >= 16) {return true;}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using whitespace to make the blocks more readable:

Example:

if (age >= 16) {
  return true;
} else if (age < 16) {  // Tip: You can just use else instead of else-if here
  return false;
}

else if (age < 16) {return false;}
}

console.log(canDrive(29));
/* Create an array called `dataTypes` with atleast 1 of every data type;
* (there are 6 different data types);
*/

function findDataType (dataTypes) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice attempt. This portion of the test is asking you to just create an array called dataTypes and to add data to it.
No need to create a function, or a for loop.

var dataTypes = [];  // Put values into this array


var types = ['hello', true, null, undefined, 20, 'dog'];

for ( var i = 0; i < types.length; i++ ) {
dataTypes = types[i];

if ( dataTypes === null ) {
dataTypes.push( null );
}
else {
dataTypes.push( typeof types );
}
}
}
findDataType ();
types.should.include( 'string' );
types.should.include( 'number' );
types.should.include( 'undefined' );
types.should.include( 'object' );
types.should.include( 'boolean' );
types.should.include( null );



/* Create a Dog object
* it should have a `bark` function that makes your dog bark!
* It should also have a name attribute with the value of 'Spot'
*/
function bark (sound, name){

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to wrap the dog object in a bark function, you want it to be the other way around!

Very similar to js-calculator, you want the dog object to have a bark method.

var dog = {
  // ...
  bark: function () {
    // ...
  }
};

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for each of these tips Tony!


var dog = {

name: 'Spot',
age: 15,
color: 'yellow',
sound: 'bark',
};

return name + " " + "really likes to" + " " + sound + "!";
}
console.log(bark('bark', 'Spot'));