JavaScript用递归方法打印出菱形图案。
就类似于这种菱形,不过要用递归的方法
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>菱形</title>
<script>
function ling(){
for(var a=4;a>-5;a--){
for(var b=-5;b<5;b++){
if(Math.abs(a)+Math.abs(b)<5){
document.write("*");
}else{
document.write("-");
}
}
document.write("<br/>");
}
}
ling();
</script>
</head>
<body>
</body>
</html>