通过JS将整数拆分为多个整数之和

通过JavaScript将一个整数拆分为多个整数之和,如果是普通需求可以按照以下代码

		var num = 100; //定义整数
		var amount= 7;  //定义多个整数的数量
		var numArr = [];
		while(amount > 1){
		    var rnd = Math.floor(Math.random() * num); //通过JS的随机函数生成随机数
		    num -= rnd;
		    numArr.push(rnd);
		    amount --;
		}
		numArr.push(num);
		console.log(numArr);

可以生成随机数组,例如:[50, 16, 24, 2, 2, 0, 6] 、[66, 14, 4, 4, 8, 1, 3] 等。

通过修改num 和 amount 可以定义不同的整数和需要拆分的整数个数。

在Codecademy完成jQuery的学习

上个月,偶看完成《在Codecademy学习HTML+CSS》,最近在入门JavaScript和jQuery。今天,偶看终于在Codecademy把jQuery相关入门练习完成。包括:

Introducing jQuery, 14 练习

In this lesson, you’ll learn about the Document Object Model (DOM), how to manipulate HTML elements with jQuery, and create web page elements that change opacity when you hover over them.

2 jQuery Functions, 13 练习

Now that you know some jQuery basics, we’ll dive into some of the details relating to fundamental jQuery actions (called functions). We’ll even make a sliding panel for a website!

3 Dynamic HTML, 14 练习

In this course, we’ll cover how to create dynamic HTML (DHTML), including how to add and remove classes (and even entire elements!) to and from our site, ultimately creating an updatable list for our webpage.

4 jQuery Events, 12 练习

You already know a few jQuery events. In this lesson, we’ll learn additional events and use them to animate a video game character.

5 jQuery Effects, 14 练习

You already know several jQuery effects. In this lesson, we’ll learn additional effects (including jQuery UI effects) and use them to create an interactive menu for our website.

6 Code ‘n Tell

Use what you’ve learned to create your own custom web application!

jQuery_Codecademy

偶看下一步要完成的是JavaScript。