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")

  • 相关阅读:
    Google's Innovation Factory (and how testing adapts)
    虎年拜年帖
    [ZZ]让测试也敏捷起来
    Selenimu做爬虫续
    OKR的解说
    春秋航空的机上店铺
    免费TK域名试用
    快速排序_C语言实现
    第一篇博客
    C、C++代码格式优化软件献给编程爱好者
  • 原文地址:https://www.cnblogs.com/LilyLiya/p/14260393.html
Copyright © 2011-2022 走看看