zoukankan      html  css  js  c++  java
  • loops; simple to do list

    • while loop VS if loop:

       while loop, we don't know when the loop will stop, if loop, we know how many times the loop will run.

    • FOR......OF......
    let subarrays = ['hello', 'hi', 'how are you'];
    
    for (let sub of subarrays) {
        console.log(sub);
    }
    • Nested For...Of
    const SECRET = "HiBye";
    
    let guess = prompt("enter the secret code……");
    while(guess !== SECRET){
         guess = prompt("enter the secret code……");
    }
    console.log("Congrats you got the secret !!!")
    • To-do-list project
      • <!DOCTYPE html>
        <html lang="en">
        
        <head>
            <meta charset="UTF-8">
            <meta name="viewport" content="width=device-width, initial-scale=1.0">
            <title>Todo List</title>
        </head>
        
        <body>
            <h1>Todo List</h1>
        
            <ul>
                <li>"new" -Add a Todo</li>
                <li>"list" - List All Todos</li>
                <li>"delete" - Remove Specific Todo</li>
                <li>"quit" - Quit App</li>
            </ul>
            <script src="todos.js"></script>
        </body>
        
        </html>
        let input = prompt("what would you like to do?");
        
        const todos = [];
        
        while (input !== "quit" && input !== "q") {
            if (input === "list") {
                console.log("**********")
                for (let i = 0; i < todos.length; i++) {
                    console.log(`${i}: ${todos[i]}`);
                }
                console.log("**********")
            } else if (input === "new") {
                const newTodo = prompt("ok, what is the new todo?");
                todos.push(newTodo);
                console.log(`${newTodo} added into the list`)
            } else if (input === "delete") {
                const index = parseInt(prompt("ok, enter an index to delete"));
                if (!Number.isNaN(index)) {
                    const deleted = todos.splice(index, 1);
                    console.log(`ok, deleted ${deleted[0]}`);
                } else {
                    console.log("Unknow index")
                }
            }
            input = prompt("what would you like to do?")
        }
        console.log("ok, quit the app")

  • 相关阅读:
    Centos 7.3 配置Xmanager XDMCP
    xstart使用方法
    Linux下安装xwindow图形界面
    使用Xftp连接Centos 6.6服务器详细图文教程
    linux远程管理器
    xftp的使用教程
    CentOS 7 关闭图形界面
    Java反射机制
    java反射的性能问题
    Java 虚拟机面试题全面解析(干货)
  • 原文地址:https://www.cnblogs.com/LilyLiya/p/14260393.html
Copyright © 2011-2022 走看看