1 //handsome 2 /** 3 *ugly 4 **/
1 // 举例 2 var myName; 3 4 // Define myName below this line
1 // Setup 2 var a; 3 var b = 2; 4 5 // Only change code below this line 6 var a = 7; 7 var b = a;
1 // 举例 2 var ourVar = 19; 3 4 // Only change code below this line 5 6 var a = 9;
1 // Initialize these three variables 2 var a = 5; 3 var b = 10; 4 var c = "I am a"; 5 6 // Do not change code below this line 7 8 a = a + 1; 9 b = b + 5; 10 c = c + " String!";
1 // Declarations 2 var studlyCapVar; 3 var properCamelCase; 4 var titleCaseOver; 5 6 // Assignments 7 studlyCapVar = 10; 8 properCamelCase = "A String"; 9 titleCaseOver = 9000;
1 var sum = 10 + 10;
1 var difference = 45 - 33;
1 var product = 8 * 10;
1 var quotient = 66 / 33;
1 var myVar = 87; 2 3 // Only change code below this line 4 myVar++;
1 var myVar = 11; 2 3 // Only change code below this line 4 myVar--;
1 var ourDecimal = 5.7; 2 3 // Only change code below this line 4 5 6 var myDecimal = 5.7;
1 var product = 2.0 * 2.5;
1 var quotient = 4.4 / 2.0;
1 // Only change code below this line 2 3 var remainder = 11 % 3;
1 var a = 3; 2 var b = 17; 3 var c = 12; 4 5 // Only modify code below this line 6 7 a += 12; 8 b += 9; 9 c += 7;
1 var a = 11; 2 var b = 9; 3 var c = 3; 4 5 // Only modify code below this line 6 7 a -= 6; 8 b -= 15; 9 c -= 1;
1 var a = 5; 2 var b = 12; 3 var c = 4.6; 4 5 // Only modify code below this line 6 7 a *= 5; 8 b *= 3; 9 c *= 10;
1 var a = 48; 2 var b = 108; 3 var c = 33; 4 5 // Only modify code below this line 6 7 a /= 12; 8 b /= 4; 9 c /= 11;
1 function convert(celsius) { 2 // Only change code below this line 3 var fahrenheit = 32 + celsius * 9 / 5; 4 5 // Only change code above this line 6 return fahrenheit; 7 } 8 9 // Change the inputs below to test your code 10 convert(30);
1 // 举例 2 var firstName = "Alan"; 3 var lastName = "Turing"; 4 5 // Only change code below this line 6 var myFirstName = "zhong"; 7 var myLastName = "liu";
1 var myStr = "I am a \"double quoted\" string inside \"double quotes\""; // Change this line
1 var myStr = 'Link';
1 var myStr = "\\ \t \r \n";
1 // 举例 2 var ourStr = "I come first. " + "I come second."; 3 4 // Only change code below this line 5 6 var myStr = "This is the start. " + "This is the end.";
1 // 举例 2 var ourStr = "I come first. "; 3 ourStr += "I come second."; 4 5 // Only change code below this line 6 7 var myStr = "This is the first sentence. "; 8 myStr += "This is the second sentence.";
1 // 举例 2 var ourName = "Free Code Camp"; 3 var ourStr = "Hello, our name is " + ourName + ", how are you?"; 4 5 // Only change code below this line 6 var myName = "edward"; 7 var myStr = "My name is " + myName + " and I am swell!";
1 // 举例 2 var anAdjective = "awesome!"; 3 var ourStr = "Free Code Camp is "; 4 ourStr += anAdjective; 5 6 // Only change code below this line 7 8 var someAdjective = "happy"; 9 var myStr = "Learning to code is "; 10 myStr += someAdjective;
1 // 举例 2 var firstNameLength = 0; 3 var firstName = "Ada"; 4 5 firstNameLength = firstName.length; 6 7 // Setup 8 var lastNameLength = 0; 9 var lastName = "Lovelace"; 10 11 // Only change code below this line. 12 13 lastNameLength = lastName.length;
1 // 举例 2 var firstLetterOfFirstName = ""; 3 var firstName = "Ada"; 4 5 firstLetterOfFirstName = firstName[0]; 6 7 // Setup 8 var firstLetterOfLastName = ""; 9 var lastName = "Lovelace"; 10 11 // Only change code below this line 12 firstLetterOfLastName = lastName[0];
1 // Setup 2 var myStr = "Jello World"; 3 4 // Only change code below this line 5 6 myStr = "Hello World"; // Fix Me
1 // 举例 2 var firstName = "Ada"; 3 var secondLetterOfFirstName = firstName[1]; 4 5 // Setup 6 var lastName = "Lovelace"; 7 8 // Only change code below this line. 9 var thirdLetterOfLastName = lastName[2];
1 // 举例 2 var firstName = "Ada"; 3 var lastLetterOfFirstName = firstName[firstName.length - 1]; 4 5 // Setup 6 var lastName = "Lovelace"; 7 8 // Only change code below this line. 9 var lastLetterOfLastName = lastName[lastName.length - 1];
1 // 举例 2 var firstName = "Ada"; 3 var thirdToLastLetterOfFirstName = firstName[firstName.length - 3]; 4 5 // Setup 6 var lastName = "Lovelace"; 7 8 // Only change code below this line 9 var secondToLastLetterOfLastName = lastName[lastName.length - 2];
1 function wordBlanks(myNoun, myAdjective, myVerb, myAdverb) { 2 var result = ""; 3 // Your code below this line 4 result = myAdjective + " " + myNoun + " " + myVerb + " " + myAdverb; 5 // Your code above this line 6 return result; 7 } 8 9 // Change the words here to test your function 10 wordBlanks("dog", "big", "ran", "quickly");
1 // 举例 2 var array = ["John", 23]; 3 4 // Only change code below this line. 5 var myArray = ["Edward",23,"China","173cm"];
1 // 举例 2 var ourArray = [["the universe", 42], ["everything", 101010]]; 3 4 // Only change code below this line. 5 var myArray = [["quan",24],["Edward",23]];
1 // 举例 2 var ourArray = [1,2,3]; 3 var ourData = ourArray[0]; // equals 1 4 5 // Setup 6 var myArray = [1,2,3]; 7 8 // Only change code below this line. 9 10 var myData = myArray[0];
1 // 举例 2 var ourArray = [1,2,3]; 3 ourArray[1] = 3; // ourArray now equals [1,3,3]. 4 5 // Setup 6 var myArray = [1,2,3]; 7 8 // Only change code below this line. 9 10 myArray[0] = 3;
1 // Setup 2 var myArray = [[1,2,3], [4,5,6], [7,8,9], [[10,11,12], 13, 14]]; 3 4 // Only change code below this line. 5 var myData = myArray[2][1];
1 // 举例 2 var ourArray = ["Stimpson", "J", "cat"]; 3 ourArray.push(["happy", "joy"]); 4 // ourArray now equals ["Stimpson", "J", "cat", ["happy", "joy"]] 5 6 // Setup 7 var myArray = [["John", 23], ["cat", 2]]; 8 9 // Only change code below this line. 10 11 myArray.push(["dog",3]);
1 // 举例 2 var ourArray = [1,2,3]; 3 var removedFromOurArray = ourArray.pop(); 4 // removedFromOurArray now equals 3, and ourArray now equals [1,2] 5 6 // Setup 7 var myArray = [["John", 23], ["cat", 2]]; 8 9 // Only change code below this line. 10 var removedFromMyArray = myArray.pop();
1 // 举例 2 var ourArray = ["Stimpson", "J", ["cat"]]; 3 removedFromOurArray = ourArray.shift(); 4 // removedFromOurArray now equals "Stimpson" and ourArray now equals ["J", ["cat"]]. 5 6 // Setup 7 var myArray = [["John", 23], ["dog", 3]]; 8 9 // Only change code below this line. 10 var removedFromMyArray = myArray.shift();
1 // 举例 2 var ourArray = ["Stimpson", "J", "cat"]; 3 ourArray.shift(); // ourArray now equals ["J", "cat"] 4 ourArray.unshift("Happy"); 5 // ourArray now equals ["Happy", "J", "cat"] 6 7 // Setup 8 var myArray = [["John", 23], ["dog", 3]]; 9 myArray.shift(); 10 11 // Only change code below this line. 12 13 myArray.unshift(["Paul",35]);
1 var myList = [["soap",3],["toothbrush",2],["tissue",3],["shoes",2],["wallet",1]];
1 // 举例 2 function ourFunction() { 3 console.log("Heyya, World"); 4 } 5 6 ourFunction(); 7 8 // Only change code below this line 9 function myFunction(){ 10 console.log("Hi World"); 11 } 12 13 myFunction();
1 // 举例 2 function ourFunction(a, b) { 3 console.log(a - b); 4 } 5 ourFunction(10, 5); // Outputs 5 6 7 // Only change code below this line. 8 function myFunction(a,b){ 9 console.log(a + b); 10 } 11 12 myFunction(3,4);
1 // Declare your variable here 2 var myGlobal =10; 3 4 function fun1() { 5 // Assign 5 to oopsGlobal Here 6 oopsGlobal = 5; 7 } 8 9 // Only change code above this line 10 function fun2() { 11 var output = ""; 12 if (typeof myGlobal != "undefined") { 13 output += "myGlobal: " + myGlobal; 14 } 15 if (typeof oopsGlobal != "undefined") { 16 output += " oopsGlobal: " + oopsGlobal; 17 } 18 console.log(output); 19 }
1 function myFunction() { 2 var myVar = 'use strict'; 3 4 5 console.log(myVar); 6 } 7 myFunction(); 8 9 // run and check the console 10 // myVar is not defined outside of myFunction 11 12 13 // now remove the console log line to pass the test
1 // Setup 2 var outerWear = "T-Shirt"; 3 4 function myFunction() { 5 // Only change code below this line 6 7 var outerWear = "sweater"; 8 9 // Only change code above this line 10 return outerWear; 11 } 12 13 myFunction();
1 // 举例 2 function minusSeven(num) { 3 return num - 7; 4 } 5 6 // Only change code below this line 7 8 function timesFive(number){ 9 return number * 5; 10 }
1 // 举例 2 var changed = 0; 3 4 function change(num) { 5 return (num + 5) / 3; 6 } 7 8 changed = change(10); 9 10 // Setup 11 var processed = 0; 12 13 function process(num) { 14 return (num + 3) / 5; 15 } 16 17 // Only change code below this line 18 19 processed = process(7);
1 function queue(arr, item) { 2 // Your code here 3 arr.push(item); 4 item = arr[0]; 5 arr.shift(); 6 return item;// Change this line 7 } 8 9 // Test Setup 10 var testArr = [1,2,3,4,5]; 11 12 // Display Code 13 console.log("Before: " + JSON.stringify(testArr)); 14 console.log(queue(testArr, 6)); // Modify this line to test 15 console.log("After: " + JSON.stringify(testArr));
1 function welcomeToBooleans() { 2 3 // Only change code below this line. 4 5 return true; // Change this line 6 7 // Only change code above this line. 8 }
1 // 举例 2 function ourFunction(isItTrue) { 3 if (isItTrue) { 4 return "Yes, it's true"; 5 } 6 return "No, it's false"; 7 } 8 9 // Setup 10 function myFunction(wasThatTrue) { 11 12 // Only change code below this line. 13 if(wasThatTrue == true){ 14 return "That was true"; 15 }else{ 16 return "That was false"; 17 } 18 19 20 // Only change code above this line. 21 22 } 23 24 // Change this value to test 25 myFunction(false);
1 // Setup 2 function myTest(val) { 3 if (val == 12) { // Change this line 4 return "Equal"; 5 } 6 return "Not Equal"; 7 } 8 9 // Change this value to test 10 myTest(10);
1 // Setup 2 function myTest(val) { 3 if (val === 7) { // Change this line 4 return "Equal"; 5 } 6 return "Not Equal"; 7 } 8 9 // Change this value to test 10 myTest(10);
1 // Setup 2 function myTest(val) { 3 if (val != 99) { // Change this line 4 return "Not Equal"; 5 } 6 return "Equal"; 7 } 8 9 // Change this value to test 10 myTest(10);
1 // Setup 2 function myTest(val) { 3 // Only Change Code Below this Line 4 5 if (val !== 17) { 6 7 // Only Change Code Above this Line 8 9 return "Not Equal"; 10 } 11 return "Equal"; 12 } 13 14 // Change this value to test 15 myTest(10);
1 function myTest(val) { 2 if (val > 100) {// Change this line 3 return "Over 100"; 4 } 5 6 if (val > 10) {// Change this line 7 return "Over 10"; 8 } 9 10 return "10 or Under"; 11 } 12 13 // Change this value to test 14 myTest(10);
1 function myTest(val) { 2 if (val >= 20) {// Change this line 3 return "20 or Over"; 4 } 5 6 if (val >= 10) {// Change this line 7 return "10 or Over"; 8 } 9 10 return "9 or Under"; 11 } 12 13 // Change this value to test 14 myTest(10);
1 function myTest(val) { 2 if (val < 25) {// Change this line 3 return "Under 25"; 4 } 5 6 if (val < 55) {// Change this line 7 return "Under 55"; 8 } 9 10 return "55 or Over"; 11 } 12 13 // Change this value to test 14 myTest(10);
1 function myTest(val) { 2 if (val <= 12) {// Change this line 3 return "Smaller Than or Equal to 12"; 4 } 5 6 if (val <= 24) {// Change this line 7 return "Smaller Than or Equal to 24"; 8 } 9 10 return "25 or More"; 11 } 12 13 // Change this value to test 14 myTest(10);
1 function myTest(val) { 2 // Only change code below this line 3 4 if (val <= 50 && val >=25) { 5 6 return "Yes"; 7 8 } 9 10 // Only change code above this line 11 return "No"; 12 } 13 14 // Change this value to test 15 myTest(10);
1 function myTest(val) { 2 // Only change code below this line 3 4 if (val<10 || val >20) { 5 return "Outside"; 6 } else { 7 return "Inside"; 8 } 9 // Only change code above this line 10 } 11 12 13 // Change this value to test 14 myTest(15);
1 function myTest(val) { 2 var result = ""; 3 // Only change code below this line 4 5 if (val > 5) { 6 result = "Bigger than 5"; 7 } else { 8 result = "5 or Smaller"; 9 } 10 11 // Only change code above this line 12 return result; 13 } 14 15 // Change this value to test 16 myTest(4);
1 function myTest(val) { 2 if (val > 10) { 3 return "Greater than 10"; 4 } else if (val < 5) { 5 return "Smaller than 5"; 6 } else { 7 return "Between 5 and 10"; 8 } 9 } 10 // Change this value to test 11 myTest(7);
1 function myTest(val) { 2 if (val < 5) { 3 return "Less than 5"; 4 } else if (val < 10) { 5 return "Less than 10"; 6 } else { 7 return "Greater than or equal to 10"; 8 } 9 } 10 11 // Change this value to test 12 myTest(7);
1 function myTest(num) { 2 // Only change code below this line 3 if (num < 5) { 4 return "Tiny"; 5 } else if(num < 10){ 6 return "Small"; 7 } else if(num < 15){ 8 return "Medium"; 9 } else if(num < 20){ 10 return "Large"; 11 } else { 12 return "Huge"; 13 } 14 // Only change code above this line 15 } 16 17 // Change this value to test 18 myTest(7);
1 function golfScore(par, strokes) { 2 // Only change code below this line 3 if (strokes == 1) { 4 return "Hole-in-one!"; 5 } else if(strokes <= par-2 ){ 6 return "Eagle"; 7 } else if(strokes == par-1){ 8 return "Birdie"; 9 } else if(strokes == par){ 10 return "Par"; 11 } else if(strokes == par+1){ 12 return "Bogey"; 13 } else if(strokes == par+2){ 14 return "Double Bogey"; 15 } else { 16 return "Go Home!"; 17 } 18 // Only change code above this line 19 } 20 21 // Change these values to test 22 golfScore(5, 4);
1 function myTest(val) { 2 var answer = ""; 3 // Only change code below this line 4 switch (val) { 5 case 1: 6 answer = "alpha"; 7 break; 8 case 2: 9 answer = "beta"; 10 break; 11 case 3: 12 answer = "gamma"; 13 break; 14 default: 15 answer = "delta"; 16 // code 17 } 18 19 20 // Only change code above this line 21 return answer; 22 } 23 24 // Change this value to test 25 myTest(1);
1 function myTest(val) { 2 var answer = ""; 3 // Only change code below this line 4 switch (val) { 5 case 'a': 6 answer = "apple"; 7 break; 8 case 'b': 9 answer = "bird"; 10 break; 11 case 'c': 12 answer = "cat"; 13 break; 14 default: 15 answer = "stuff"; 16 } 17 18 19 // Only change code above this line 20 return answer; 21 } 22 23 // Change this value to test 24 myTest(1);
1 function myTest(val) { 2 var answer = ""; 3 // Only change code below this line 4 switch (val) { 5 case 1: 6 case 2: 7 case 3: 8 answer = "Low"; 9 break; 10 case 4: 11 case 5: 12 case 6: 13 answer = "Mid"; 14 break; 15 case 7: 16 case 8: 17 case 9: 18 answer = "High"; 19 break; 20 default: 21 // code 22 } 23 24 25 // Only change code above this line 26 return answer; 27 } 28 29 // Change this value to test 30 myTest(1);
1 function myTest(val) { 2 var answer = ""; 3 // Only change code below this line 4 switch (val) { 5 case 'bob': 6 answer = "Marley"; 7 break; 8 case 42: 9 answer = "The Answer"; 10 break; 11 case 1: 12 answer = "There is no #1"; 13 break; 14 case 99: 15 answer = "Missed me by this much!"; 16 break; 17 case 7: 18 answer = "Ate Nine"; 19 break; 20 default: 21 } 22 23 24 25 // Only change code above this line 26 return answer; 27 } 28 29 // Change this value to test 30 myTest(7);
1 function isLess(a, b) { 2 // Fix this code 3 return a<b; 4 } 5 6 // Change these values to test 7 isLess(10, 15);
1 // Setup 2 function abTest(a, b) { 3 // Only change code below this line 4 if ( a<0 || b<0 ) { 5 return undefined; 6 } 7 8 9 // Only change code above this line 10 11 return Math.round(Math.pow(Math.sqrt(a) + Math.sqrt(b), 2)); 12 } 13 14 // Change values below to test your code 15 abTest(2,2);
1 var count = 0; 2 3 function cc(card) { 4 // Only change code below this line 5 switch (card) { 6 case 2: 7 case 3: 8 case 4: 9 case 5: 10 case 6: 11 count++; 12 break; 13 case 10: 14 case 'J': 15 case 'Q': 16 case 'K': 17 case 'A': 18 count--; 19 break; 20 default: 21 } 22 23 if (count > 0) { 24 return count+" Bet"; 25 } else { 26 return count+" Hold"; 27 } 28 29 // Only change code above this line 30 } 31 32 // Add/remove calls to test your function. 33 // 提示: Only the last will display 34 cc(2);
1 // 举例 2 var ourDog = { 3 "name": "Camper", 4 "legs": 4, 5 "tails": 1, 6 "friends": ["everything!"] 7 }; 8 9 // Only change code below this line. 10 11 var myDog = { 12 "name" : "Laffy", 13 "legs" : 4, 14 "tails" : 1, 15 "friends" :["edward","viola"] 16 17 18 };
1 // Setup 2 var testObj = { 3 "hat": "ballcap", 4 "shirt": "jersey", 5 "shoes": "cleats" 6 }; 7 8 // Only change code below this line 9 10 var hatValue = testObj.hat;// Change this line 11 var shirtValue = testObj.shirt;// Change this line
1 // Setup 2 var testObj = { 3 "an entree": "hamburger", 4 "my side": "veggies", 5 "the drink": "water" 6 }; 7 8 // Only change code below this line 9 10 var entreeValue = testObj["an entree"]; // Change this line 11 var drinkValue = testObj["the drink"];// Change this line
1 // Setup 2 var testObj = { 3 12: "Namath", 4 16: "Montana", 5 19: "Unitas" 6 }; 7 8 // Only change code below this line; 9 10 var playerNumber = 16; // Change this Line 11 var player = testObj[playerNumber]; // Change this Line
1 // 举例 2 var ourDog = { 3 "name": "Camper", 4 "legs": 4, 5 "tails": 1, 6 "friends": ["everything!"] 7 }; 8 9 ourDog.name = "Happy Camper"; 10 11 // Setup 12 var myDog = { 13 "name": "Coder", 14 "legs": 4, 15 "tails": 1, 16 "friends": ["Free Code Camp Campers"] 17 }; 18 19 myDog.name = "Happy Coder"; 20 // Only change code below this line.
1 // 举例 2 var ourDog = { 3 "name": "Camper", 4 "legs": 4, 5 "tails": 1, 6 "friends": ["everything!"] 7 }; 8 9 ourDog.bark = "bow-wow"; 10 11 // Setup 12 var myDog = { 13 "name": "Happy Coder", 14 "legs": 4, 15 "tails": 1, 16 "friends": ["Free Code Camp Campers"] 17 }; 18 19 // Only change code below this line. 20 21 myDog.bark = "woof";
1 // 举例 2 var ourDog = { 3 "name": "Camper", 4 "legs": 4, 5 "tails": 1, 6 "friends": ["everything!"], 7 "bark": "bow-wow" 8 }; 9 10 delete ourDog.bark; 11 12 // Setup 13 var myDog = { 14 "name": "Happy Coder", 15 "legs": 4, 16 "tails": 1, 17 "friends": ["Free Code Camp Campers"], 18 "bark": "woof" 19 }; 20 21 // Only change code below this line. 22 23 delete myDog.tails;
1 // Setup 2 function phoneticLookup(val) { 3 var result = ""; 4 5 // Only change code below this line 6 var lookup = { 7 "alpha" : "Adams", 8 "bravo" : "Boston", 9 "charlie" : "Chicago", 10 "delta" : "Denver", 11 "echo" : "Easy", 12 "foxtrot" : "Frank" 13 } 14 15 result = lookup[val]; 16 17 // Only change code above this line 18 return result; 19 } 20 21 // Change this value to test 22 phoneticLookup("charlie");
1 // Setup 2 var myObj = { 3 gift: "pony", 4 pet: "kitten", 5 bed: "sleigh" 6 }; 7 8 function checkObj(checkProp) { 9 // Your Code Here 10 if (myObj.hasOwnProperty(checkProp)) { 11 return myObj[checkProp]; 12 } 13 return "Not Found"; 14 } 15 16 // Test your code by modifying these values 17 checkObj("gift");
1 var myMusic = [ 2 { 3 "artist" : "Billy Joel", 4 "title" : "Piano Man", 5 "release_year" : 1973, 6 "formats" : [ 7 "CS", 8 "8T", 9 "LP" ], 10 "gold" : true 11 }, 12 // Add record here 13 { 14 "artist" : "Jay", 15 "title" : "依然范特西", 16 "release_year" : 2008, 17 "formats" : [ 18 "Fang", 19 "Cai"], 20 "gold" : false 21 } 22 ];
1 // Setup 2 var myStorage = { 3 "car": { 4 "inside": { 5 "glove box": "maps", 6 "passenger seat": "crumbs" 7 }, 8 "outside": { 9 "trunk": "jack" 10 } 11 } 12 }; 13 14 // Only change code below this line 15 16 var gloveBoxContents = myStorage.car.inside["glove box"]; // Change this line
1 // Setup 2 var myPlants = [ 3 { 4 type: "flowers", 5 list: [ 6 "rose", 7 "tulip", 8 "dandelion" 9 ] 10 }, 11 { 12 type: "trees", 13 list: [ 14 "fir", 15 "pine", 16 "birch" 17 ] 18 } 19 ]; 20 21 // Only change code below this line 22 23 var secondTree = myPlants[1].list[1]; // Change this line
1 // Setup 2 var collection = { 3 2548: { 4 album: "Slippery When Wet", 5 artist: "Bon Jovi", 6 tracks: [ 7 "Let It Rock", 8 "You Give Love a Bad Name" 9 ] 10 }, 11 2468: { 12 album: "1999", 13 artist: "Prince", 14 tracks: [ 15 "1999", 16 "Little Red Corvette" 17 ] 18 }, 19 1245: { 20 artist: "Robert Palmer", 21 tracks: [ ] 22 }, 23 5439: { 24 album: "ABBA Gold" 25 } 26 }; 27 // Keep a copy of the collection for tests 28 var collectionCopy = JSON.parse(JSON.stringify(collection)); 29 30 // Only change code below this line 31 function update(id, prop, value) { 32 33 if (value !== '' && prop != 'tracks') { 34 collectionCopy[id][prop] = value; 35 } else if(value !== '' && prop == 'tracks'){ 36 collectionCopy[id][prop].push(value); 37 } else { 38 delete collectionCopy[id][prop]; 39 } 40 41 return collection; 42 } 43 44 // Alter values below to test your code 45 update(5439, "artist", "ABBA");
1 // 举例 2 var ourArray = []; 3 4 for (var i = 0; i < 5; i++) { 5 ourArray.push(i); 6 } 7 8 // Setup 9 var myArray = []; 10 11 // Only change code below this line. 12 var a; 13 for(a = 1;a < 6;a++){ 14 myArray.push(a); 15 }
1 // 举例 2 var ourArray = []; 3 4 for (var i = 0; i < 10; i += 2) { 5 ourArray.push(i); 6 } 7 8 // Setup 9 var myArray = []; 10 11 // Only change code below this line. 12 for (var i = 1; i < 10; i += 2) { 13 myArray.push(i); 14 }
1 // 举例 2 var ourArray = []; 3 4 for (var i = 10; i > 0; i -= 2) { 5 ourArray.push(i); 6 } 7 8 // Setup 9 var myArray = []; 10 11 // Only change code below this line. 12 for (var i = 9; i > 0 ; i -= 2) { 13 myArray.push(i); 14 }
1 // 举例 2 var ourArr = [ 9, 10, 11, 12]; 3 var ourTotal = 0; 4 5 for (var i = 0; i < ourArr.length; i++) { 6 ourTotal += ourArr[i]; 7 } 8 9 // Setup 10 var myArr = [ 2, 3, 4, 5, 6]; 11 12 // Only change code below this line 13 var total = 0; 14 for (var i = 0; i < myArr.length; i++) { 15 total += myArr[i]; 16 }
1 function multiplyAll(arr) { 2 var product = 1; 3 // Only change code below this line 4 for (var i = 0; i < arr.length; i++) { 5 for(var j = 0; j < arr[i].length; j++){ 6 product *= arr[i][j]; 7 } 8 } 9 // Only change code above this line 10 return product; 11 } 12 13 // Modify values below to test your code 14 multiplyAll([[1,2],[3,4],[5,6,7]]);
1 // Setup 2 var myArray = []; 3 4 // Only change code below this line. 5 var i = 0; 6 while(i <= 4){ 7 myArray.push(i); 8 i++; 9 }
1 //Setup 2 var contacts = [ 3 { 4 "firstName": "Akira", 5 "lastName": "Laine", 6 "number": "0543236543", 7 "likes": ["Pizza", "Coding", "Brownie Points"] 8 }, 9 { 10 "firstName": "Harry", 11 "lastName": "Potter", 12 "number": "0994372684", 13 "likes": ["Hogwarts", "Magic", "Hagrid"] 14 }, 15 { 16 "firstName": "Sherlock", 17 "lastName": "Holmes", 18 "number": "0487345643", 19 "likes": ["Intriguing Cases", "Violin"] 20 }, 21 { 22 "firstName": "Kristian", 23 "lastName": "Vos", 24 "number": "unknown", 25 "likes": ["Javascript", "Gaming", "Foxes"] 26 } 27 ]; 28 29 30 function lookUpProfile(firstName, prop){ 31 // Only change code below this line 32 var hasName = false; 33 for (var i = 0; i < contacts.length; i++) { 34 if (contacts[i].firstName == firstName) { 35 hasName = true; 36 if (contacts[i].hasOwnProperty(prop)) { 37 return contacts[i][prop]; 38 } else { 39 return "No such property"; 40 } 41 } 42 } 43 44 if(!hasName){ 45 return "No such contact"; 46 } 47 // Only change code above this line 48 } 49 50 // Change these values to test your function 51 lookUpProfile("Akira", "likes");
1 function randomFunction() { 2 3 // Only change code below this line. 4 5 return Math.random(); 6 7 // Only change code above this line. 8 }
1 var randomNumberBetween0and19 = Math.floor(Math.random() * 20); 2 3 function myFunction() { 4 5 // Only change code below this line. 6 7 return Math.floor(Math.random() * 10); 8 }
1 // 举例 2 function ourFunction(ourMin, ourMax) { 3 4 return Math.floor(Math.random() * (ourMax - ourMin + 1)) + ourMin; 5 } 6 7 ourFunction(1, 9); 8 9 // Only change code below this line. 10 11 function randomRange(myMin, myMax) { 12 13 return Math.floor(Math.random() * (myMax - myMin + 1)) + myMin; // Change this line 14 15 } 16 17 // Change these values to test your function 18 var myRandom = randomRange(5, 15);
1 // Setup 2 var testString = "Ada Lovelace and Charles Babbage designed the first computer and the software that would have run on it."; 3 4 // 举例 5 var expressionToGetSoftware = /software/gi; 6 var softwareCount = testString.match(expressionToGetSoftware).length; 7 8 9 // Only change code below this line. 10 11 var expression = /and/gi;// Change this Line 12 13 // Only change code above this line 14 15 // This code counts the matches of expression in testString 16 var andCount = testString.match(expression).length;
1 // Setup 2 var testString = "There are 3 cats but 4 dogs."; 3 4 // Only change code below this line. 5 6 var expression = /\d+/g;// Change this line 7 8 // Only change code above this line 9 10 // This code counts the matches of expression in testString 11 var digitCount = testString.match(expression).length;
1 // Setup 2 var testString = "How many spaces are there in this sentence?"; 3 4 // Only change code below this line. 5 6 var expression = /\s+/g;// Change this line 7 8 // Only change code above this line 9 10 // This code counts the matches of expression in testString 11 var spaceCount = testString.match(expression).length;
1 // Setup 2 var testString = "How many non-space characters are there in this sentence?"; 3 4 // Only change code below this line. 5 6 var expression = /\S/g;// Change this line 7 8 // Only change code above this line 9 10 // This code counts the matches of expression in testString 11 var nonSpaceCount = testString.match(expression).length;
106
综合运用开发游戏
1 33 343563 64366237 3840FCC Slot Machine
39415142 434445 464748 4950
5253 5657
5859 6061
1 39 404169 70426843 4446FCC Slot Machine
45475748 495051 525354 5556
5859 6263
6465 6667
1 43 444573 74467247 4850FCC Slot Machine
49516152 535455 565758 5960
6263 6667
6869 7071
1 41 424371 72447045 4648FCC Slot Machine
47495950 515253 545556 5758
6061 6465
6667 6869