-
Notifications
You must be signed in to change notification settings - Fork 195
revised basics #12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
revised basics #12
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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')); | ||
|
|
||
|
|
||
| /* 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')); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| /* 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;} | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 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){ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need to wrap the Very similar to js-calculator, you want the var dog = {
// ...
bark: function () {
// ...
}
};
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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')); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need for a
Personfunction.