61-Comparison with the Less Than Or Equal To Operator
functiontestLessOrEqual(val){if (val<=12) {// Change this linereturn"Smaller Than or Equal to 12";}if (val<=24) {// Change this linereturn"Smaller Than or Equal to 24";}return"25 or More";}// Change this value to testtestLessOrEqual(10);
62-Comparisons with the Logical And Operator
functiontestLogicalAnd(val){ // Only change code below this lineif ( val<=50&&val>=25 ) {return"Yes";} // Only change code above this linereturn"No";}// Change this value to testtestLogicalAnd(10);
63-Comparisons with the Logical Or Operator
64-Introducing Else Statements
65-Introducing Else If Statements
66-Logical Order in If Else Statements
67-Chaining If Else Statements
68-Golf Code
69-Selecting from many options with Switch Statements
70-Adding a default option in Switch statements
71-Multiple Identical Options in Switch Statements
72-Replacing If Else Chains with Switch
73-Returning Boolean Values from Functions
74-Return Early Pattern for Functions
75-Counting Cards
76-Build JavaScript Objects
77-Accessing Objects Properties with the Dot Operator
78-Accessing Objects Properties with Bracket Notation
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);
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);
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);
function orderMyLogic(val) {
if (val < 5) {
return "Less than 5";
} else if (val < 10) {
return "Less than 10";
} else {
return "Greater than or equal to 10";
}
}
// Change this value to test
orderMyLogic(7);
function testSize(num) {
// Only change code below this line
var result = "";
if (num>=20){
result = "Huge";
}
else if (num<5){
result = "Tiny";
}
else if (num<10){
result = "Small";
}
else if (num<15){
result = "Medium";
}
else if (num<20){
result = "Large";
}
return result;
// Only change code above this line
}
// Change this value to test
testSize(19);
function golfScore(par, strokes) {
// Only change code below this line
var result = "";
if (strokes==1){
result = "Hole-in-one!";
}
else if (strokes<=par-2){
result = "Eagle";
}
else if (strokes==par-1){
result = "Birdie";
}
else if (strokes===par){
result = "Par";
}
else if (strokes==par+1){
result = "Bogey";
}
else if (strokes==par+2){
result = "Double Bogey";
}
else if (strokes>=par+3){
result = "Go Home!";
}
return result;
// Only change code above this line
}
// Change these values to test
golfScore(5, 4);
function caseInSwitch(val) {
var answer = "";
// Only change code below this line
switch (val){
case 1:
answer = "alpha";
break;
case 2:
answer = "beta";
break;
case 3:
answer = "gamma";
break;
case 4:
answer = "delta";
break;
}
// Only change code above this line
return answer;
}
// Change this value to test
caseInSwitch(1);
function switchOfStuff(val) {
var answer = "";
// Only change code below this line
switch(val){
case "a":
answer = "apple";
break;
case "b":
answer = "bird";
break;
case "c":
answer = "cat";
break;
default:
answer = "stuff";
}
// Only change code above this line
return answer;
}
// Change this value to test
switchOfStuff("a");
function sequentialSizes(val) {
var answer = "";
// Only change code below this line
switch(val){
case 1:
case 2:
case 3:
answer = "Low";
break;
case 4:
case 5:
case 6:
answer = "Mid";
break;
case 7:
case 8:
case 9:
answer = "High";
break;
}
// Only change code above this line
return answer;
}
// Change this value to test
sequentialSizes(1);
function chainToSwitch(val) {
var answer = "";
// Only change code below this line
switch(val){
case "bob":
answer = "Marley";
break;
case 42:
answer = "The Answer";
break;
case 1:
answer = "There is no #1";
break;
case 99:
answer = "Missed me by this much!";
break;
case 7:
answer = "Ate Nine";
break;
}
// Only change code above this line
return answer;
}
// Change this value to test
chainToSwitch(7);
function isLess(a, b) {
// Fix this code
return a < b;
}
// Change these values to test
isLess(10, 15);
// Setup
function abTest(a, b) {
// Only change code below this line
if (a<0 || b<0){
return undefined;
}
// Only change code above this line
return Math.round(Math.pow(Math.sqrt(a) + Math.sqrt(b), 2));
}
// Change values below to test your code
abTest(2,2);
var count = 0;
function cc(card) {
// Only change code below this line
switch(card){
case 2:
case 3:
case 4:
case 5:
case 6:
count = count + 1;
break;
case 7:
case 8:
case 9:
break;
case 10:
case "J":
case "Q":
case "K":
case "A":
count = count -1;
break;
}
if(count===0){
return "0 Hold";
}
else if(count>0){
return count + " Bet";
}
else if(count<0){
return count + " Hold";
}
// Only change code above this line
}
// Add/remove calls to test your function.
// Note: Only the last will display
cc(2); cc(3); cc(7); cc('K'); cc('A');
// Example
var ourDog = {
"name": "Camper",
"legs": 4,
"tails": 1,
"friends": ["everything!"]
};
// Only change code below this line.
var myDog = {
"name": "snoopy",
"legs": 2,
"tails": 1,
"friends": ["lala", "xixi"]
};
// Setup
var testObj = {
"hat": "ballcap",
"shirt": "jersey",
"shoes": "cleats"
};
// Only change code below this line
var hatValue = testObj.hat; // Change this line
var shirtValue = testObj.shirt; // Change this line
// Setup
var testObj = {
"an entree": "hamburger",
"my side": "veggies",
"the drink": "water"
};
// Only change code below this line
var entreeValue = testObj["an entree"]; // Change this line
var drinkValue = testObj["the drink"]; // Change this line
// Setup
var testObj = {
12: "Namath",
16: "Montana",
19: "Unitas"
};
// Only change code below this line;
var playerNumber = 16; // Change this Line
var player = testObj[playerNumber]; // Change this Line
// Example
var ourDog = {
"name": "Camper",
"legs": 4,
"tails": 1,
"friends": ["everything!"]
};
ourDog.name = "Happy Camper";
// Setup
var myDog = {
"name": "Coder",
"legs": 4,
"tails": 1,
"friends": ["Free Code Camp Campers"]
};
myDog.name = "Happy Coder";
// Only change code below this line.
// Example
var ourDog = {
"name": "Camper",
"legs": 4,
"tails": 1,
"friends": ["everything!"]
};
ourDog.bark = "bow-wow";
// Setup
var myDog = {
"name": "Happy Coder",
"legs": 4,
"tails": 1,
"friends": ["Free Code Camp Campers"]
};
myDog.bark = "woof";
// Only change code below this line.
// Example
var ourDog = {
"name": "Camper",
"legs": 4,
"tails": 1,
"friends": ["everything!"],
"bark": "bow-wow"
};
delete ourDog.bark;
// Setup
var myDog = {
"name": "Happy Coder",
"legs": 4,
"tails": 1,
"friends": ["Free Code Camp Campers"],
"bark": "woof"
};
delete myDog.tails;
// Only change code below this line.
// Setup
function phoneticLookup(val) {
var result = "";
// Only change code below this line
var lookup = {
alpha:"Adams",
bravo: "Boston",
charlie: "Chicago",
delta: "Denver",
echo: "Easy",
foxtrot: "Frank"
};
result = lookup[val];
// Only change code above this line
return result;
}
// Change this value to test
phoneticLookup("charlie");
- 有空格的屬性,用
// Setup
var myStorage = {
"car": {
"inside": {
"glove box": "maps",
"passenger seat": "crumbs"
},
"outside": {
"trunk": "jack"
}
}
};
// Only change code below this line
var gloveBoxContents = myStorage.car.inside["glove box"]; // Change this line
// Setup
var myPlants = [
{
type: "flowers",
list: [
"rose",
"tulip",
"dandelion"
]
},
{
type: "trees",
list: [
"fir",
"pine",
"birch"
]
}
];
// Only change code below this line
var secondTree = myPlants[1].list[1]; // Change this line
// Example
var ourArray = [];
for (var i = 0; i < 5; i++) {
ourArray.push(i);
}
// Setup
var myArray = [];
for (var i = 1; i < 6; i++){
myArray.push(i);
}
// Only change code below this line.
// Example
var ourArray = [];
for (var i = 0; i < 10; i += 2) {
ourArray.push(i);
}
// Setup
var myArray = [];
for (var i = 1; i < 10; i += 2){
myArray.push(i);
}
// Only change code below this line.
// Example
var ourArray = [];
for (var i = 10; i > 0; i -= 2) {
ourArray.push(i);
}
// Setup
var myArray = [];
// Only change code below this line.
for (var i=9; i>0; i-=2){
myArray.push(i);
}