Skip to content

Instantly share code, notes, and snippets.

@fushang318
Created July 3, 2013 07:53
Show Gist options
  • Save fushang318/5916181 to your computer and use it in GitHub Desktop.
Save fushang318/5916181 to your computer and use it in GitHub Desktop.

来源

http://www.codecademy.com/courses/javascript-beginner-en-6LzGd/0/1?curriculum_id=506324b3a7dffd00020bf661

章节名

第一章 JS函数

课件名

第一课 函数入门1

json

{\"title\":\"Meet the Functions\",\"desc\":\"\",\"kind\":\"javascript\",\"total_count\":5,\"steps\":[{\"content\":\"\",\"rule\":\"if (error) {\\r\\n  return false;\\r\\n}\\r\\n\\r\\n\\r\\nif (balance != 20.97) {\\r\\n  return false;\\r\\n}\\r\\n\\r\\n\\r\\nreturn true;\",\"title\":\"\\u521d\\u59cb\\u4ecb\\u7ecd\",\"desc\":\"1, \\u5982\\u679c balance \\u5c0f\\u4e8e 10, \\u4f7f\\u7528 console.log \\u8f93\\u51fa balance - 5 \\r\\n \\r\\n2, \\u5426\\u5219\\uff0c\\u4f7f\\u7528 console.log \\u8f93\\u51fa balance.\\r\\n\",\"hint\":\"\",\"init_code\":\"var balance = 20.97;\\r\\n\\r\\n// Complete the condition in the ()s on line 4\\r\\nif (balance ) {\\r\\n  // console.log() the balance minus 5 dollars\\r\\n\\t\\r\\n} else {\\r\\n\\t// Just console.log() the balance\\r\\n}\"},{\"content\":\"\",\"rule\":\"return true;\",\"title\":\"\\u51fd\\u6570\\u4ecb\\u7ecd\",\"desc\":\"1, \\u7b2c 3 \\u884c\\u58f0\\u660e\\u4e86\\u4e00\\u4e2a\\u51fd\\u6570\\r\\n\\r\\n2, \\u7b2c 4 \\u884c \\u8ddf \\u7b2c 5 \\u884c, \\u82b1\\u62ec\\u53f7 {}  \\u91cc\\u9762\\u7684\\u8fd9\\u6bb5\\u4ee3\\u7801\\u4f1a\\u88ab\\u53cd\\u590d\\u4f7f\\u7528\\r\\n\\r\\n3, \\u7b2c 4 \\u884c\\u58f0\\u660e\\u4e86\\u4e00\\u4e2a\\u53d8\\u91cf val,  \\u7b2c 5 \\u884c\\u628a\\u8fd9\\u4e2a\\u53d8\\u91cf\\u8f93\\u51fa\\r\\n\\r\\n4,  \\u7b2c 8 - 11 \\u884c\\u4ee3\\u7801\\u6ce8\\u89e3\\r\\n\\r\\n5, \\u7b2c 12 \\u884c \\u7528\\u5176\\u5b83\\u7684\\u6570\\u503c\\u4ee3\\u66ff 6 \\uff0c\\u63d0\\u4ea4\\u5e76\\u4fdd\\u5b58\\u4ee3\\u7801\\uff0c\\u591a\\u8bd5\\u51e0\\u6b21\\uff0c\\u4f53\\u9a8c\\u4e0b\\u51fd\\u6570\\u7684\\u5947\\u5999\",\"hint\":\"\",\"init_code\":\"// This is what a function looks like:\\r\\n\\r\\nvar divideByThree = function (number) {\\r\\n    var val = number / 3;\\r\\n    console.log(val);\\r\\n};\\r\\n\\r\\n// On line 11, we call the function by name\\r\\n// Here, it is called 'dividebythree'\\r\\n// We tell the computer what the number input is (i.e. 6)\\r\\n// The computer then uses the code inside the function!\\r\\ndivideByThree(6);\"},{\"content\":\"\",\"rule\":\"if (error instanceof ReferenceError) {\\r\\n  return false;\\r\\n}\\r\\n\\r\\nif (error) {\\r\\n  return false;\\r\\n}\\r\\n\\r\\nif (MT.calls('greeting').length === 0) {\\r\\n  return false;\\r\\n}\\r\\n\\r\\nreturn true;\\r\\n\",\"title\":\"\\u51fd\\u6570\\u8bed\\u6cd5\",\"desc\":\"\\u51fd\\u6570 4 \\u4e2a\\u6b65\\u9aa4\\r\\n1 \\u4f7f\\u7528 var \\u58f0\\u660e\\u51fd\\u6570\\r\\n\\r\\n2 \\u4f7f\\u7528\\u5173\\u952e\\u5b57 function, \\u544a\\u8bc9\\u8ba1\\u7b97\\u673a\\uff0c\\u4f60\\u6b63\\u5728\\u521b\\u5efa\\u4e00\\u4e2a\\u51fd\\u6570\\r\\n\\r\\n3 \\u5706\\u62ec\\u53f7\\u91cc\\u9762\\u7684\\u53d8\\u91cf\\u79f0\\u4e4b\\u4e3a\\u53c2\\u6570\\r\\n\\r\\n4 \\u5728 {} \\u5927\\u62ec\\u53f7\\u91cc\\u9762\\u5b8c\\u6210\\u4ee3\\u7801\\u5757\",\"hint\":\"\\u5728\\u7b2c 11 \\u884c\\uff0c\\u8c03\\u7528 greeting  \\u5e76\\u4f20\\u5165\\u4e00\\u4e2a\\u5b57\\u7b26\\u4e32\\u503c\",\"init_code\":\"// Below is the greeting function!\\r\\n// See line 7\\r\\n// We can join strings together using the plus sign (+)\\r\\n// See the hint for more details about how this works.\\r\\n\\r\\nvar greeting = function (name) {\\r\\n    console.log(\\\"Great to see you,\\\" + \\\" \\\" + name);\\r\\n};\\r\\n\\r\\n// On line 11, call the greeting function!\"},{\"content\":\"1 \\u58f0\\u540d\\u4e00\\u4e2a\\u51fd\\u6570\\uff0c\\u547d\\u540d\\u4e3a 'foodDemand`\\r\\n\\r\\n2 \\u4f20\\u4e00\\u4e2a\\u540d\\u4e3a food \\u7684\\u53c2\\u6570\\r\\n\\r\\n3 \\u5728\\u4ee3\\u7801\\u5757\\u91cc\\u5b9e\\u73b0 console.log(\\\"I want to eat\\\" + \\\" \\\" + food);\\r\\n   \\r\\n4 \\u8c03\\u7528\\u8be5\\u51fd\\u6570\\uff0c\\u5e76\\u4f20\\u4e00\\u4e2a\\u4f60\\u60f3\\u8981\\u7684 'food' \\u503c\",\"rule\":\"if (error instanceof ReferenceError) {\\r\\n  return false;\\r\\n}\\r\\n\\r\\nif (error) {\\r\\n  return false;\\r\\n}\\r\\n\\r\\nif (typeof foodDemand !== 'function') {\\r\\n  return false;\\r\\n}\\r\\n    \\r\\nif (MT.calls(\\\"foodDemand\\\").length === 0) {\\r\\n  return false;\\r\\n}\\r\\n\\r\\nif (MT.prints.length === 0) {\\r\\n  return false;\\r\\n}\\r\\n    \\r\\nreturn true;\\r\\n\",\"title\":\"\\u51fd\\u6570\\u5982\\u4f55\\u5de5\\u4f5c\",\"desc\":\"\\u8ba9\\u6211\\u4eec\\u6765\\u5256\\u6790\\u51fd\\u6570\\u5728\\u8ba1\\u7b97\\u673a\\u91cc\\u9762\\u662f\\u5982\\u4f55\\u8fd0\\u8f6c\\u7684\\r\\n\\r\\nvar functionName = function( ) {\\r\\n    code code code;\\r\\n    code code code;\\r\\n    (more lines of code); \\r\\n};\\r\\n\\r\\n1 var \\u53d8\\u91cf\\u58f0\\u660e\\u51fd\\u6570\\r\\n\\r\\n2  var \\u540e\\u9762\\u7d27\\u8ddf\\u4e00\\u4e2a\\u53d8\\u91cf\\r\\n\\r\\n3 \\u5173\\u952e\\u5b57 function \\u544a\\u8bc9\\u8ba1\\u7b97\\u673a\\u8fd9\\u662f\\u4e00\\u4e2a\\u51fd\\u6570\\uff0c\\u4e0d\\u662f\\u5176\\u5b83\\u522b\\u7684 \\r\\n\\r\\n4 \\u5706\\u62ec\\u53f7\\u91cc\\u9762\\u7684\\u53c2\\u6570\\u4f1a\\u4f20\\u5230\\u4ee3\\u7801\\u5757\\u91cc\\u8fd0\\u884c\\r\\n\\r\\n5 \\u82b1\\u62ec\\u53f7 { } \\u91cc\\u9762\\u7684\\u4ee3\\u7801\\u5757\\u4f1a\\u88ab\\u53cd\\u590d\\u8fd0\\u884c. \\u82b1\\u62ec\\u53f7 { } \\u91cc\\u9762\\u7684\\u6bcf\\u884c\\u4ee3\\u7801\\u5fc5\\u987b\\u4ee5\\u5206\\u53f7\\u7ed3\\u675f \\r\\n\\r\\n6 \\u6574\\u4e2a\\u51fd\\u6570\\u4ee5\\u5206\\u53f7\\u7ed3\\u675f\\r\\n\",\"hint\":\"\",\"init_code\":\"// Write your foodDemand function below.\\r\\n// Last hint: In your reusable block of code, end each line\\r\\n// with a semicolon (;)\\r\\n\"},{\"content\":\"\\u82b1\\u62ec\\u53f7\\u91cc\\u9762\\u7684\\u6bcf\\u4e00\\u884c\\u7ed3\\u5c3e\\u90fd\\u8981\\u4ee5\\u5206\\u53f7\\u7ed3\\u5c3e\",\"rule\":\"try {\\r\\n  greeting;\\r\\n}\\r\\ncatch (ReferenceError) {\\r\\n  return false;\\r\\n}\\r\\n\\r\\nif (error instanceof ReferenceError){\\r\\n  return false;\\r\\n}\\r\\n\\r\\nif (error) {\\r\\n  return false;\\r\\n}\\r\\n\\r\\nif (MT.calls('greeting').length === 0)\\r\\n  return false;\\r\\n\\r\\nreturn true;\\r\\n\",\"title\":\"\\u603b\\u7ed3\",\"desc\":\"\\u4e3a\\u4ec0\\u4e48\\u65e0\\u6cd5\\u8fd0\\u884c\\uff0c\\u8ba9\\u6211\\u4eec\\u6765\\u8c03\\u8bd5\\u770b\\u770b\\r\\n\\r\\n1  \\u7b2c 9 \\u884c\\uff0c\\u6709\\u5f88\\u591a\\u8bed\\u6cd5\\u9519\\u8bef\\uff0c\\u5982\\u679c\\u6ca1\\u6709\\u7a7a\\u683c\\uff0c\\u8c03\\u8bd5\\u8d77\\u6765\\u5c06\\u4f1a\\u591a\\u4e48\\u9ebb\\u70e6\\r\\n\\r\\n2 \\u4fee\\u6b63\\u7b2c 9 \\u884c\\uff0c\\u4f7f\\u5b83\\u8bed\\u6cd5\\u6b63\\u786e\\uff0c\\u5e76\\u4e14\\u770b\\u8d77\\u6765\\u4ee3\\u7801\\u6bd4\\u8f83\\u5bb9\\u6613\\u8bfb\\u61c2\\r\\n\\r\\n3 \\u5982\\u679c\\u4fee\\u6b63\\u597d\\u7684\\u8bdd\\uff0c\\u8c03\\u7528  greeting \\u51fd\\u6570\\uff0c\\u522b\\u5fd8\\u4e86\\u4f20\\u4e00\\u4e2a\\u7279\\u522b\\u7684\\u53c2\\u6570\\u540d\\r\\n\\r\\n\",\"hint\":\"\",\"init_code\":\"// Nicely written function:\\r\\nvar calculate = function (number) {\\r\\n    var val = number * 10;\\r\\n    console.log(val);\\r\\n};\\r\\n\\r\\n// Badly written function with syntax errors!\\r\\n\\r\\ngreeting var func{name}(console.log(name)))} \"}]}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment