20180223
字符串加变量的写法,参照上面的举例即可。
var myName = "XiaoMing";var myStr = "My name is" + myName + "and I am swell!";
#161 Appending Variables to Strings
字符串追加操作
var someAdjective = "good!";
var myStr = "Learning to code is ";
myStr += someAdjective;#162 Find the Length of a String
找字符串长度,这一节比较有用了,我发现我接触的编程语言大多数都是这么写,变量名加上“.”后面跟上功能定义,类似于我们说话,中间的”.“类似于“的”比如“myfinger.length"类似于“我手指的手指数”。
lastNameLength = lastName.length;
用索引找到字符串中第一个字符,这里需要注意,在编程语言中,第一个字符是从0开始的
firstLetterOfLastName = lastName[0];
#164 Understand String Immutability
理解字符串的不可变性,注意:在javascript中,字符串的值是不可变的
myStr = "Hello World"; // 请修改这一行
#165 Use Bracket Notation to Find the Nth Character in a String
用索引在字符串中查找指定位置的字符
var thirdLetterOfLastName = lastName[2];
#166 Use Bracket Notation to Find the Last Character in a String
用索引查找字符串中的最后一个字符,也等同于用索引查找字符串中的字符串长度-1的字符
var lastLetterOfLastName = lastName[lastName.length -1];
#167 Use Bracket Notation to Find the NthtoLast Character in a String
用索引找到字符串中倒数第N个字符。
var secondToLastLetterOfLastName = lastName[lastName.length -2];
#168 Word Blanks
填词造句,注意这里面要求单词中间要有空格,否则就是一个长的字符串,所以每个变量后面要加“空格”。
// 请把你的代码写在这条注释以下
result = myNoun +" " + myAdjective + " " + myVerb + " " + myAdverb;myNoun ="cat ";
myAdjective = "little ";
myVerb = "hit ";
myAdverb = "slowly ";
// 请把你的代码写在这条注释以上
return result;
}
wordBlanks("cat", "little", "hit", "slowly"); // 你可以修改这一行来测试你的代码
#169 Store Multiple Values in one Variable using JavaScript Arrays
使用JavaScript数组将多个值存储在一个变量中,这个简单,按照举例的写就可以。
var myArray = ["xiaoming", 27];
#170 Nest one Array within Another Array
多维数组,就是数组嵌套数组,按照举例来做。
var myArray = [["xiaoming", 27],["lilei", 22],["hanmeimei",21]];
#180 Access Array Data with Indexes
用索引访问数组数据
// 初始化变量
var myArray = [1,2,3];var myData = myArray[0];
// 请把你的代码写在这条注释以下
#181 Modify Array Data With Indexes
用索引修改数组的数据
// 请把你的代码写在这条注释以下
myArray[0] = 3;#182 Access MultiDimensional Arrays With Indexes
用索引访问多维数组
// 请只修改这条注释以下的代码
var myData = myArray[2][1];#183 Manipulate Arrays With push
末尾追加数据
// 初始化变量
var myArray = [["John", 23], ["cat", 2]];// 请把你的代码写在这条注释以下
myArray.push(["dog",3]);
#184 Manipulate Arrays With pop
抛出函数.pop()
// 请只修改这条注释以下的代码
var removedFromMyArray = myArray.pop();#185 Manipulate Arrays With shift
用shift移出第一个元素
// 请只修改这条注释以下的代码
var removedFromMyArray = myArray.shift();
#186 Manipulate Arrays With unshift
用unshift插入数组到头部。
// 请把你的代码写在这条注释以下
myArray.unshift(["Paul",35]);#187 Shopping List
购物清单,实际上就是定义一个数组
var myList = [["鸡蛋",25],["酱油",8],["挂面",15],["康师傅方便面",6.9],["牛奶",30]];
#188 Write Reusable JavaScript with Functions
编写可重用的JavaScript函数。很多初学者对函数都有一点恐惧,其实函数解释起来很简单,就是把你所有的定义的变量或者行为封装在一起,说简单点就是用大括号扩在一起,这样可以方便程序调用,减少重复的代码量。
// 请把你的代码写在这条注释以下function myFunction(){
console.log("Hi World");
}
#189 Passing Values to Functions with Arguments
与参数值传递给函数
// 请把你的代码写在这条注释以下
function myFunction(a, b){
console.log(a + b);
}
myFunction(1,2);
#190 Global Scope and Functions
全局作用域和功能,全局变量在函数外,函数内的变量只能在函数内起作用
// 请在这里把 5 赋值给 oopsGlobal
oopsGlobal = 5;}
var myGlobal = 10;
// 请只修改这条注释以上的代码