js foundation Exercises (2)

5. Functions

Packaging according to claim 1. The two functions

1.封装一个函数,要求输入字符串转化成数组弹出

2.封装一个函数,要求能求出三个数中的最小值,注意:不准使用js内置函数

2. a function package, and the unknown parameters, note: not fixed parameters

3. have the following code

function fn(a, b, c) {
  return a + b + c
}

Modify the code to a, b, c Set Default

4. Write a function add, to get the results this way calling

var a = add(2)(3)(4);
console.log(a)  // 9

The reading program, write results

var a = 1
function fn1(){
  function fn2(){
    console.log(a)
  }
  function fn3(){
    var a = 4
    fn2()
  }
  var a = 2
  return fn3
}
var fn = fn1()
fn() //输出多少

6. The reading program, write results

var a = 1
function fn1(){
  function fn3(){
    var a = 4
    fn2()
  }
  var a = 2
  return fn3
}
function fn2(){
  console.log(a)
}
var fn = fn1()
fn() //输出多少

7. recursively find the factorial of n

The following is called, the function completion buy

buy('xiaoming','apple',function(){
    alert("shopping finish");
});
9.根据下面的调用方式,补全fn函数

var a = fn([1, 2, 3, 4], function (item, index, arr) {
  if (item > 2) {
    return item + 1
  } else {
    return item - 1
  }
})
console.log(a)  // [0, 1, 4, 5]

10. Read the following paragraphs procedures, write results

function foo(){
    function bar() {
        return 3;
    }
    return bar();
    function bar() {
        return 8;
    }
}
alert(foo());
function foo(){
    var bar = function() {
        return 3;
    };
    return bar();
    var bar = function() {
        return 8;
    };
}
alert(foo());
alert(foo());
function foo(){
    var bar = function() {
        return 3;
    };
    return bar();
    var bar = function() {
        return 8;
    };
}
function foo(){
    return bar();
    var bar = function() {
        return 3;
    };
    var bar = function() {
        return 8;
    };
}
alert(foo());

6. Event

1. Packaging a generic event binding function listenEvent

2. Packages cancel a generic event binding function stopListening

3. encapsulates a generic prevent the event's default behavior is a function of preventEvent

4. The function of the package prevents a generic event bubbling cancelPropagation

5. Write a demo, the direction control block

6. have the following code, write js achieve click the button corresponding pop-up button buttons subscript

<button>1</button>
<button>2</button>
<button>3</button>
<button>4</button>
<button>5</button>
<button>6</button>

7. Write a demo, load a single image

var imgsrc = 'http://edu.nodeing.com/files/system/block_picture_1516379328.jpg?version=8.2.14'

8. Write a demo, load multiple images, in order to load

var mulitImg = [
        'http://edu.nodeing.com/files/system/block_picture_1516373242.jpg?version=8.2.14',
        'http://edu.nodeing.com/files/system/block_picture_1516588307.jpg?version=8.2.14',
        'http://edu.nodeing.com/files/system/block_picture_1516374079.jpg?version=8.2.14',
        'http://edu.nodeing.com/files/system/block_picture_1516379328.jpg?version=8.2.14'
    ]

9. Write a Demo, acquires coordinates of the mouse in a box, the coordinate origin is the upper left vertex of the block

10. Write a demo, using the new HTML5 drag and drop complete the following effect

7. Browser

1. Write prompted for confirmation before a demo, realize delete a line element

2. How to open a web page in a browser window

3. How to close a window

4. How the window into the specified location

5. How to get the version number of the browser

6. How to jump page, and how to refresh the page

7. How to build a breadcrumb navigation path

8. How to implement a browser with js forward, backward, jump specify History page

9. How to change the picture in a page according to the size of the browser window size

Screw classroom video lessons Address: http://edu.nodeing.com

Guess you like

Origin www.cnblogs.com/dadifeihong/p/12028324.html