Skip to content

Instantly share code, notes, and snippets.

@chrisdhanaraj
Last active August 29, 2015 14:07
Show Gist options
  • Select an option

  • Save chrisdhanaraj/3641aec8189527a0226f to your computer and use it in GitHub Desktop.

Select an option

Save chrisdhanaraj/3641aec8189527a0226f to your computer and use it in GitHub Desktop.
JS Jamz Quiz #1
// Write a function that returns its argument.
// Write a function that takes a name and returns the length of the name.
// Write a function that takes two numbers, adds them, and returns the result.
// Write a function that takes an object and adds the key:value pair of "France" : "Paris" to it. Return the object.
@chrisdhanaraj

Copy link
Copy Markdown
Author

Danni: 30
Laura: 20

@chrisdhanaraj

Copy link
Copy Markdown
Author

// Write a function that returns its argument.
// Write a function that takes a name and returns the length of the name.
// Write a function that takes two numbers, adds them, and returns the result.
// Write a function that takes an object and adds the key:value pair of "France" : "Paris" to it. Return the object

// Write a function that returns its argument.
// Testing the definition of a function

function answerOne(result) {
return result;
}

console.log(answerOne('the answer!'));
// returns 'the answer!'

// Write a function that takes a name and returns the length of the name.
// Testing string functions, .length

function nameLength(name) {
return name.length;
}

var danniLength = nameLength('danni');
// returns 4

// Write a function that takes two numbers, adds them, and returns the result.
// testing basic math

function add(x, y) {
return x + y;
}

// Write a function that takes an object and adds the key:value pair of "France" : "Paris" to it. Return the object
// testing object properties

function addValue(obj){
obj['France'] = 'Paris';
return obj;
}

obj = {
'United States' : 'Washington D.C.',
'Canada' : 'Ottawa'
}

addValue(obj);
console.log(obj);
/*
{
'United States' : 'Washington D.C.',
'Canada' : 'Ottawa',
'France': 'Paris'
}
*/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment