diff --git "a/\347\277\201\347\253\240\345\275\25401/.keep" "b/\347\277\201\347\253\240\345\275\25401/.keep" new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git "a/\347\277\201\347\253\240\345\275\25401/2022-11-16 \347\273\203\344\271\2402022_2021_20\347\272\247js\346\234\237\346\234\253\350\200\203 1-7.md" "b/\347\277\201\347\253\240\345\275\25401/2022-11-16 \347\273\203\344\271\2402022_2021_20\347\272\247js\346\234\237\346\234\253\350\200\203 1-7.md" new file mode 100644 index 0000000000000000000000000000000000000000..14a9a31df3bb9b5d6a8a0fad62805acb840d02d6 --- /dev/null +++ "b/\347\277\201\347\253\240\345\275\25401/2022-11-16 \347\273\203\344\271\2402022_2021_20\347\272\247js\346\234\237\346\234\253\350\200\203 1-7.md" @@ -0,0 +1,161 @@ +```html +// 题目如下,请直接利用写好的方法,并且直接写在题目下方,要可以运行和输出,如第1题所示 + + /* + 1、题目描述: + 找出元素 item 在给定数组 arr 中的位置 + 输出描述: + 如果数组中存在 item,则返回元素在数组中的位置,否则返回 -1 + 示例1 indexOf + 输入 + [ 1, 2, 3, 4,3 ], 3 + 输出 + 2 + + function indexOf(arr, item) { + + } + */ + console.log(`======= 第1题 =======`); + const arr =[1, 2, 3, 4, 5]; + function indexOf(arr, item) { + return arr.indexOf(3); + } + console.log(indexOf(arr,3)); + /* + 2、题目描述: + 计算给定数组 arr 中所有元素的总和 reduce() every()(some()) map() filter() forEach() + 输入描述: + 数组中的元素均为 Number 类型 + 示例1 + 输入 + + [ 1, 2, 3, 4 ] + 输出 + + 10 + + function sum(arr) { + + } + */ + console.log(`======= 第2题 =======`); + const arr1 =[1, 2, 3, 4]; + function sum(arr) { + var sum1 = 0; + for(var a of arr){ + sum1+=a; + } + return sum1; + } + console.log(sum(arr1)); + /* + 3、题目描述 + 在数组 arr 末尾添加元素 item。不要直接修改数组 arr,结果返回新的数组 + 示例1 + 输入 + + [1, 2, 3, 4], 10 + 输出 + + [1, 2, 3, 4, 10] + + function append(arr, item) { + + } + */ + console.log(`======= 第3题 =======`); + const arr2 = [1, 2, 3, 4]; + function append(arr, item) { + arr.push(item); + return arr; + } + console.log(append(arr2,10)); + /* + 4、题目描述 + 合并数组 arr1 和数组 arr2。不要直接修改数组 arr,结果返回新的数组 + 示例1 + 输入 + + [1, 2, 3, 4], ['a', 'b', 'c', 1] + 输出 + + [1, 2, 3, 4, 'a', 'b', 'c', 1] + + function concat(arr1, arr2) { + + } + */ + console.log(`======= 第4题 =======`); + const arr3 = [1, 2, 3, 4]; + const arr4 = ['a', 'b', 'c', 1]; + function concat(arr1, arr2) { + var arr = arr1.concat(arr2); + return arr; + } + console.log(concat(arr3,arr4)); + /* + 5、题目描述 + 为数组 arr 中的每个元素求二次方。不要直接修改数组 arr,结果返回新的数组 + 示例1 + 输入 + + [1, 2, 3, 4] + 输出 + + [1, 4, 9, 16] + + function square(arr) { + + } + */ + console.log(`======= 第5题 =======`); + const arr5 = [1, 2, 3, 4]; + function square(arr) { + return arr.map((n)=>{ + return n*n + }); + } + console.log(square(arr5)); + /* + 6、题目描述 + 定义一个计算圆面积的函数area_of_circle(),它有两个参数: + + r: 表示圆的半径; + pi: 表示π的值,如果不传,则默认3.14 + + function area_of_circle(r, pi) { + + } + */ + console.log(`======= 第6题 =======`); + function area_of_circle(r,pi=3.14){ + console.log(pi*r*r); + } + area_of_circle(5); + + /* + 7、题目描述 + 用jQuery编程实现获取选中复选框值的函数abc + HTML结构如下: +
+ 0 + 1 + 2 + 3 + +
+
+ + */ + console.log(`======= 第7题 =======`); + function abc() { + var checkbox = document.getElementsByName('aa'); + for (var index = 0; index < checkbox.length; index++) { + if (checkbox[index].checked) { + console.log(checkbox[index].value); + } + } + } +``` +