鄭紹麒Python寫入檔案vs JAVASCRIPT寫入網頁document

CSS程式碼

h1{background-color: rgb(177, 34, 34); color: white; border: 10px solid rgb(0, 123, 255); text-align:center; padding: 5px} ul{background-color: green; color: white; font-size: 2em;line-height:1.5} input{font-size:24px;background-color:rgb(210, 250, 215);} .monkey{font-size:36px;}

HTML程式碼

鄭紹麒輸入參數

輸入k
輸入m
輸入n

重點

alert內建函數,自訂函數abc

鄭紹麒輸出結果

JAVASCRIPT程式碼

const space=' ', slash='/', backslash='\\', cr='\n';
function row1(k,m){
    for(let i=0; i<k;i++){
        for(let ii=0; ii<m; ii++){
            for(let j=0; j<k-i-1; j++)
                out+=space;
            out+=slash;
            for(let j=0; j<2*i; j++)
                out+=space;
            out+=backslash;
            for(let j=0; j<k-i-1;j++)
                out+=space;};
    out+=cr;};};
function row2(k,m){
    for(let i=0; i<k; i++){
        for(let ii=0; ii<m; ii++){
            for(let j=0; j<i; j++)
                out+=space;
            out+=backslash;
            for(let j=0; j<2*k-2*i-2; j++)
                out+=space;
        out+=slash;
        for(let j=0; j<i;j++)
            out+=space;};
    out+=cr;};};
function abc(){
    k = document.getElementById('k').value;
    m = document.getElementById('m').value;
    n = document.getElementById('n').value;
    out ='<pre>\n';
    for(let i=0; i<n; i++){
        row1(k,m);
        row2(k,m);}
    out += '</pre>';      
    document.getElementById('out').innerHTML=out;}


留言

這個網誌中的熱門文章

鄭紹麒VScode, HTML檔案, CSS檔案, JS檔案

鄭紹麒數學方程式排版練習