-
Notifications
You must be signed in to change notification settings - Fork 8
A : FreeCodeCamp
Art dvp edited this page Dec 21, 2017
·
6 revisions
data.push()
// Example
var ourArray = ["Stimpson", "J", "cat"];
console.log(ourArray)
ourArray.push(["happy", "joy"]);
// ourArray now equals ["Stimpson", "J", "cat", ["happy", "joy"]]
// Setup
var myArray = [["John", 23], ["cat", 2]];
console.log(myArray);
// Only change code below this line.
myArray.push(["dog",3]);
console.log(ourArray);
console.log(myArray);
/*
["Stimpson", "J", "cat"]
[["John", 23], ["cat", 2]]
["Stimpson", "J", "cat", ["happy", "joy"]]
[["John", 23], ["cat", 2], ["dog", 3]]
*/
// Example
var ourArray = [1,2,3];
console.log(ourArray);
var removedFromOurArray = ourArray.pop();
console.log(ourArray);
// removedFromOurArray now equals 3, and ourArray now equals [1,2]
// Setup
var myArray = [["John", 23], ["cat", 2]];
console.log(myArray);
// Only change code below this line.
var removedFromMyArray = myArray.pop();
console.log(myArray);
/*
[1, 2, 3]
[1, 2]
[["John", 23], ["cat", 2]]
[["John", 23]]
*/
// Example
var ourArray = ["Stimpson", "J", ["cat"]];
console.log(ourArray);
removedFromOurArray = ourArray.shift();
console.log(ourArray);
// removedFromOurArray now equals "Stimpson" and ourArray now equals ["J", ["cat"]].
// Setup
var myArray = [["John", 23], ["dog", 3]];
console.log(myArray);
// Only change code below this line.
var removedFromMyArray = myArray.shift();
console.log(myArray);
/*
["Stimpson", "J", ["cat"]]
["J", ["cat"]]
[["John", 23], ["dog", 3]]
[["dog", 3]]
*/
// Example
var ourArray = ["Stimpson", "J", "cat"];
ourArray.shift(); // ourArray now equals ["J", "cat"]
ourArray.unshift("Happy");
// ourArray now equals ["Happy", "J", "cat"]
// Setup
var myArray = [["John", 23], ["dog", 3]];
myArray.shift();
// Only change code below this line.
myArray.unshift(["Paul",35]);
//
/*
["Stimpson", "J", "cat"]
["J", "cat"]
[["John", 23], ["dog", 3]]
[["dog", 3]]
[["Paul", 35], ["dog", 3]]
*/
var myList = [["Chocolate Bar",13],["Lamud",44],["Durien",22],["Cheesebite",66],["Coke",33]];
// Example
function ourReusableFunction() {
console.log("Heyya, World");
}
ourReusableFunction();
// Only change code below this line
function reusableFunction(){
console.log("Hi World");
}
reusableFunction();
/*
"Heyya, World"
"Hi World"
*/
// Example
function ourFunctionWithArgs(a, b) {
console.log(a - b);
}
ourFunctionWithArgs(10, 5); // Outputs 5
// Only change code below this line.
function functionWithArgs(a,b){
console.log(a + b);
}
functionWithArgs(4,5);
/*
5
9
*/
// Declare your variable here
var myGlobal = 10;
function fun1() {
// Assign 5 to oopsGlobal Here
oopsGlobal = 5;
}
// Only change code above this line
function fun2() {
var output = "";
if (typeof myGlobal != "undefined") {
output += "myGlobal: " + myGlobal;
}
if (typeof oopsGlobal != "undefined") {
output += " oopsGlobal: " + oopsGlobal;
}
console.log(output);
}
fun1();
fun2();
function myLocalScope() {
'use strict';
var myVar = 4;
console.log(myVar);
}
myLocalScope();
// Run and check the console
// myVar is not defined outside of myLocalScope
console.log(myVar);
// Now remove the console log line to pass the test
/*
"ReferenceError: myVar is not defined
at null.js:11:38
at https://static.jsbin.com/js/prod/runner-4.1.1.min.js:1:13850
at https://static.jsbin.com/js/prod/runner-4.1.1.min.js:1:10792"
*/
// Setup
var outerWear = "T-Shirt";
function myOutfit() {
// Only change code below this line
var outerWear = "sweater";
// Only change code above this line
return outerWear;
}
console.log(myOutfit());
/*
"sweater"
*/
// Example
function minusSeven(num) {
return num - 7;
}
function timesFive(val) {
return val * 5;
}
// Only change code below this line
var an = timesFive(10);
console.log(an);
// Example
var changed = 0;
function change(num) {
return (num + 5) / 3;
}
changed = change(10);
// Setup
var processed = 0;
function processArg(num) {
return (num + 3) / 5;
}
// Only change code below this line
processed = processArg(7);
/*
2
*/
function nextInLine(arr, item) {
// Your code here
arr.push(item);
return arr.shift(); // Change this line
}
// Test Setup
var testArr = [1,2,3,4,5];
// Display Code
console.log("Before: " + JSON.stringify(testArr));
console.log(nextInLine(testArr, 6)); // Modify this line to test
console.log("After: " + JSON.stringify(testArr));
/*
"Before: [1,2,3,4,5]"
1
"After: [2,3,4,5,6]"
*/
function welcomeToBooleans() {
// Only change code below this line.
return true; // Change this line
// Only change code above this line.
}
/*
true
*/
// Example
function ourTrueOrFalse(isItTrue) {
if (isItTrue) {
return "Yes, it's true";
}
return "No, it's false";
}
// Setup
function trueOrFalse(wasThatTrue) {
// Only change code below this line.
if(wasThatTrue){
return "Yes, that was true";
}
return "No, that was false";
// Only change code above this line.
}
// Change this value to test
trueOrFalse(true);
trueOrFalse(false);
/*
"Yes, that was true"
"No, that was false"
*/
// Setup
function testEqual(val) {
if (val == 12) { // Change this line
return "Equal";
}
return "Not Equal";
}
// Change this value to test
testEqual(10);
/*
Not Equal
*/
// Setup
function testStrict(val) {
if (val === 7) { // Change this line
return "Equal";
}
return "Not Equal";
}
// Change this value to test
testStrict(10);
testStrict(7);
testStrict("7");
/*
"Not Equal"
"Equal"
"Not Equal"
*/
// Setup
function testNotEqual(val) {
if (val != 99) { // Change this line
return "Not Equal";
}
return "Equal";
}
// Change this value to test
testNotEqual(10);
/*
Not Equal
*/
// Setup
function testStrictNotEqual(val) {
// Only Change Code Below this Line
if (val !== 17) {
// Only Change Code Above this Line
return "Not Equal";
}
return "Equal";
}
// Change this value to test
testStrictNotEqual(10);
/*
Not Equal
*/
function testGreaterThan(val) {
if (val > 100) { // Change this line
return "Over 100";
}
if (val > 10) { // Change this line
return "Over 10";
}
return "10 or Under";
}
// Change this value to test
testGreaterThan(10);
/*
10 or Under
*/
function testGreaterOrEqual(val) {
if (val >= 20) { // Change this line
return "20 or Over";
}
if (val >= 10) { // Change this line
return "10 or Over";
}
return "9 or Under";
}
// Change this value to test
testGreaterOrEqual(10);
/*
10 or Over
*/
function testLessThan(val) {
if (val < 25) { // Change this line
return "Under 25";
}
if (val < 55) { // Change this line
return "Under 55";
}
return "55 or Over";
}
// Change this value to test
testLessThan(10);
/*
Under 25
*/
function testLessOrEqual(val) {
if (val <= 12) { // Change this line
return "Smaller Than or Equal to 12";
}
if (val <= 24) { // Change this line
return "Smaller Than or Equal to 24";
}
return "25 or More";
}
// Change this value to test
testLessOrEqual(10);
function testLogicalAnd(val) {
// Only change code below this line
if (val <= 50 && val >= 25) {
return "Yes";
}
// Only change code above this line
return "No";
}
// Change this value to test
testLogicalAnd(10);
/*
No
*/
function testLogicalOr(val) {
// Only change code below this line
if (val < 10 || val > 20 ) {
return "Outside";
}
// Only change code above this line
return "Inside";
}
// Change this value to test
testLogicalOr(15);
/*
Inside
*/
function testElse(val) {
var result = "";
// Only change code below this line
if (val > 5) {
result = "Bigger than 5";
}else{
result = "5 or Smaller";
}
// Only change code above this line
return result;
}
// Change this value to test
testElse(4);
/*
5 or Smaller
*/
function testElseIf(val) {
if (val > 10) {
return "Greater than 10";
} else if(val < 5){
return "Smaller than 5";
} else {
return "Between 5 and 10";
}
}
// Change this value to test
testElseIf(7);
/*
Between 5 and 10
*/