Sunday, October 29, 2023

Event Calendar Vanilla Javascript

        const numDays = (y, m) => new Date(y, m, 0).getDate();

        console.log(numDays(2023, 10));


        let dayone = new Date(2023, 9, 1).getDay();

        console.log(dayone+" hari pertama di bulan ini 0 untuk minggu");


        // get the last date of the month

        let lastdate = new Date(2023, 9 + 1, 0).getDate();

        console.log(lastdate+" tanggal terakhir bulan ini");


        // get the day of the last date of the month

        let dayend = new Date(2023, 9, lastdate).getDay();

        console.log(dayend+" nama hari terakhir selasa di bulan ini");


        // get the last date of the previous month

        let monthlastdate = new Date(2023, 9, 0).getDate();

        console.log(monthlastdate+" tanggal terakhir dari bulan sebelumnya");

Wednesday, October 25, 2023

Text Editor Javascript

 html

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Simple Text Editor</title>
        <link rel="stylesheet" href="./style.css" />
    </head>
    <body>
        <div>
            <p><button id="open" onclick="openFile()"> to open a file </button> | <button id="save" onclick="saveFile()" style="display:none"> to save a file </button></p>
        </div>
        <br />
        <textarea name="" id="editor" cols="80" rows="10"></textarea>

        <script src="./index.js"></script>
    </body>
</html>
 

 

Javascript

let fileHandle
const textarea = document.querySelector("textarea")

async function openFile() {
    const [handle] = await window.showOpenFilePicker()
    fileHandle = handle
    const file = await handle.getFile()
    const text = await file.text()
    textarea.value = text
    document.getElementById("save").style = 'display:block';
}

async function saveFile() {
    const writable = await fileHandle.createWritable()
    await writable.write(textarea.value)
    await writable.close()
}
 

 

 

Set Cookie dan Remove Cookie dengan php vanilla.js

< html lang = "en" > < head >     < meta charset = "UTF-8" >     < meta name = "viewport...