Skip to content

Instantly share code, notes, and snippets.

@chrisdhanaraj
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrisdhanaraj/3641aec8189527a0226f to your computer and use it in GitHub Desktop.
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.
@danniengel
Copy link

// #1

var firstVariable = function() {
console.log('hi there!');
}

function test(element) {
test(element);
}

test(firstVariable);

// ANSWER: hi there!

// #2

var name = 'danni';
name.length

// ANSWER: 5

// #3

var one = 1;
var two = 2;

one + two = 3

// ANSWER: 3

// #4

@LauraHolt
Copy link

//1
var test =['argument'];
test

//2
var name = ['Laura'];
name.length ??don't remember how to return length

//3
var number1 = ['42'];
var number2 = ['23'];
function to add both
number1 + number2

//4
var portal = {
'United Kingdom' : 'London'
};
var cube = {
'France' : 'Paris'
};
function turret()
to add functions

@chrisdhanaraj
Copy link
Author

Danni: 30
Laura: 20

@chrisdhanaraj
Copy link
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