Jiawen Zheng
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # **Tinker Javascript Part I** * Group members: Jiawen Zheng, Qihuan Zhang, Yuki Qu * Google Doc URL: https://docs.google.com/document/d/1DalHhvjOWuiuG9z--37xakA_jwm5q_JOKIJo1fE9hDg/edit ## **Articulate** - What is the STATE? * Yuki: When nothing entered by users, how the surface looks like. The initial value of the code/variable. - What is the SEQUENCE? * Yuki: Active function? How users manipulate. Like clicking, dragging, typing. - What is the CAUSALITY? * Yuki: The relationship between cause and effect. When click/ gave a certain order, how the system response. ## **Part 0** - **What do you think is the value of definitely? Is Jimmy going to the prom with Sally?** * Yes. - **How does this work? (Code, not relationships.)** * Start from `maybe(yes(no))`, we first run line 1 `yes(no)`, and it returns `no()`. Before it returns final result, `no()` is called and line 4 runs and returns "yes". So in line 2, it actually returns "yes". So line 10 becomes `maybe("yes")` and we begin run line 7, and it returns "yes". So definitely is declared and assigned "yes". - **When is the no function called?** * On line 2 inside the “yes” function - **On the line var definitely = maybe(yes(no)); there aren’t ()s immediately after no. What is the significance of this?** * This means no here served as an argument/ choice instead of a function being called. It does not need to return anything back (?). If it has a (), the code here should be the result of `no()` but not the whole code - **Explain how this code snippet works, line by line, part by part.** * Variable `x` equals to the string variable “bitter”; variable `y` equals to the string variable “sweet”; variable `z` equals to the string variable `“Coffee is ${x}, Sugar is ${y}, Monday mornings are ${x}${y}.” ` - **What does the ${} syntax represent?** * ``${x}`` has the same meaning as `` + x + ``, so it’s concatenating the literal (string) with the variable `x` and `y`. - **Why are template literals super useful for us?** * It helps us to put different variable (the value, not only the variable name) into the string instead of messing up. ## **Part 1** :::info **Parts 1-4: Breaking it Apart** It might help to start by forking the codepen into four separate pens. And for each pen, reducing/removing all unused code, i.e. both HTML and JS for that part, so that all that remains are the functional ones for that part to work. (There is a reason why I don't do this for you...) Reducing what is visually in front of you can greatly help you to focus on the bits that are relevant to the sub-problem at hand. Note that `printLog()` is utilized across multiple parts. ::: - **Click on the link at the top to view the `index-simple.html` version. Compare the HTML between this version and the Bootstrap version. Compare the JS between this version and the Bootstrap version.** - How do these two versions compare with regard to helping you understand Javascript? - HTML between index-simple vs. Bootstrap - Simple version does not have CSS, instead, it used ``<style>`` in the HTML part to format the canvas.Bootstrap version has the CSS part for formatting. - Both of the versions using ``<meta charset="UTF-8">`` in their ``<head>`` parts. *[ UTF-8: The Unicode Consortium develops the Unicode Standard. Their goal is to replace the existing character sets with its standard Unicode Transformation Format (UTF)]* - Bootstrap using `container` class every time before typing some content in. ```htmlmixed= <h1>Tinker: JS <small><a href="https://codepen.io/jmk2142/pen/zEqzjp" target="_blank">Jump to Simple Version</a></small></h1> </div> ``` * The way of using button class are different: * Bootstrap: ```htmlmixed= <button class="btn btn-default" onclick="setName()">Set Name</button> ``` * Simple: ```htmlmixed= <button onclick="setName()">Set Name</button> ``` * History for both are written in the same format. * JS between index-simple vs. Bootstrap * The JS for both simple version and Bootstrap version are very alike. * **Play with the interface (each of the buttons) and observe how the program reacts. When tinkering, try changing the order in which you play with the interface. Take note of the printed _history_.** - Explain how this program works with regard to STATE, SEQUENCE, and CAUSALITY of each line, and/or specific parts of a line as appropriate. Use specific vocabulary, as demonstrated in the notes section. - Be sure to articulate both aspects of the HTML and JS. - What does the `prompt` function return? - The prompt function returns a first name and a last name - Explain what you think the `document.querySelector()` does. Talk about this in terms of the functions vocabulary presented in the Notes. - If I told you that `document.querySelector` RETURNS something, what do you think that something is? - The Document method querySelector() returns the first Element within the document that matches the specified selector, or group of selectors. If no matches are found, null is returned. - How could you alter the `printName` function in order to print the users first and last name in the browser window tab? - How would you use the `makeFullName` function to shorten the `greetUser` and `printName` code? ## **Part 2** - **Explain how this program works with regard to STATE, SEQUENCE, and CAUSALITY of each line, and/or specific parts of a line as appropriate. Use specific vocabulary, as demonstrated in the notes section.** The SEQUENCE of this part is that the user needs to enter a username and email and then press the print the info button to show the specific updated info. The first function is `updatedUsername` and the id is `#username`. When user inputs their name, their updatedUsername will appear in the print log. The second function is `updateEmail`. It will go over the same procedure that when user inputs their emails, their updated email will appear in the print log. The next function is `printInfo`. When user click on the print info button (HTML), the input username and email will be grabbed and it will appear in the print log. The last function is `resetInfo`. When user click on the reset button, it will clear the print log while leaving the word history. The CAUSALITY is if the user does not input any info but press the print button, “no username - undefined” will be printed. However, if the user inputs the username and email, the page will have an update username with the new info. And then when the user presses the print button, their updated info will appear. What kind of events are happening in Part 2 and explain how this relates to when the handlers will run. The `document.querySelector('#username').value` in the `updatedUsername` function means that Javascript will goes to the onchange attibute in html section and select the elements with the id username . And then the content will print in the print log. Same for the updateEmail function. The `The document.querySelector('#userInfo').innerHTML `in the `printInfo` function means that Javascript will goes to the onclick attribute in the html section and work with the button to handle the event. So when user clicks on the print info button, the username and email will be printed. - **What is `event.target`?** The variable email is declared by event.target and then passed to the print log to print. - **What does the dot `.value`, `.textContent`, `.innerHTML` represent in this context?** The `.value` represent the username that user inputs. The `.textContent`, `.innerHTML` represent the text that appears in the print log. But the `.innerHTML` add html features to the text. - **Why does updateEmail have a parameter for event data but the other functions do not?** I’m not sure why there must have a parameter for event data. I tried to delete it and it works fine. - **`resetInfo` is actually a little broken. Why?** Because after user reset the info, if they click print info, the previous history will print again. ## **Part 3** - **Explain how this program works with regard to STATE, SEQUENCE, and CAUSALITY of each line, and/or specific parts of a line as appropriate. Use specific vocabulary, as demonstrated in the notes section.** **STATE**: var `preEl` = `document.querySelector`('#prePartThree'); var `mysteryEl` = document.querySelector('body'); **SEQUENCE:** 1. User clicks the show image data button change element triggered `showImageData()` called with element data passed in as argument `showImageData`routine begins `ImageData` state is sent to HTML showimage data element `showImageData` routine ends 2. User clicks on the showParentData button click element triggered `showParentData()` function is called `showParentData()` routine begins `ParentData` state is sent to the HTML showparentdata element `showParentData`routine ends 3. User clicks the Show Image Data via Parent button click element triggered `showImageDataViaParent() `function is called `showImageDataViaParent()` routine begins `parentEl`state is sent to the HTML parentEl via document.querySelector. `childEl` state is sent to the HTML childEl via parentEl property of children. `showImageDataViaParent()`routine ends 4. User clicks the show Parent Via Image button click element triggered `showParentViaImage()` function is called `showImageDataViaParent()` routine begins `childEl`state is sent to the HTML via document.querySelector('#animalImage'); `parentEl` state is sent to the HTML parentEl via childEl property of parent. `showParentViaImage()` routine ends. 5. User clicks the show button data button click event triggered `showButtonData()` called with event data passed in as argument `showButtonData()` routine begins `partialData` state is sent to the HTML parentEl via event property of target. 6. User clicks the change image button Click element triggered `changeImage()` function is called `changeImage()` routine begins partialData state is sent to the HTML imgEl via document.querySelector('#animalImage') `changeImage()` routine ends. 7. User clicks the reset part three button click element triggered `resetPartThree()` function is called `resetPartThree()` routine begins partthreestate is sent to the HTML via document.querySelector('#animalImage') and document.querySelector('#prePartThree'). `resetPartThree()` routine ends. CAUSALITY: If the user doesn’t click on the buttons of show image data, show image data via parent, show parent data via image, and show this button data, there will be no info appearing. The same thing applies to the buttons change image and reset. If the user doesn’t click on those buttons, the image will stay the same. - **How do these two different functions achieve the same output?** Because the document of those two functions are both `#animalImageParent`, which makes the output appear to be the same. - **How do these two different functions achieve the same output?** Because the document of those two functions are both `#animalImage`, which makes the output appear to be the same. - **Play with the Change Image button. Can you modify the related code so that each time you pressed it, it would show 1 of 5 images, cycling through to the next image per click?** There are several ways to solve this. I changed the order of links of images in `var imgEl`. Play with the Show This Button button. - **What is the value of the property onclick of the button?** The value is `showButtonData(event)` ## **Part 4 - Challenge** - **Explain how this program works with regard to STATE, SEQUENCE, and CAUSALITY of each line, and/or specific parts of a line as appropriate. Use specific vocabulary, as demonstrated in the notes section. Be sure to articulate both aspects of the HTML and JS.** **STATE:** var selectEl = `document.querySelector`('#coffee'); var radioEl = `document.querySelector`('[name="whichDrink"]:checked') var checkboxEls = `document.querySelectorAll`('#coffeeTime input[type="checkbox"]:checked'); var times = []; for (var checkboxElement of checkboxEls) { times.push(checkboxElement.value); var textareaEl = `document.querySelector`('textarea'); textareaEl.value = ""; var `realTimeStoryEl` = `document.getElementById`('realTimeStory'); `realTimeStoryEl`.innerHTML = "No Content"; `realTimeStoryEl`.nextElementSibling.textContent = **SEQUENCE**: User selects from preferences and makes choice from querySelector('#coffee'). User clicks the checkbox to choose coffee time from the value [name="whichDrink"]. User types in text ,updateComment() called with event data passed in as argument. UpdateComment routine begins. InputElement is set to the HTML input element, via event property of target. Comment is set to the text, via the value property of inputElement. updateComment routine ends **CAUSALITY**: If user doesn’t make choices among the preferences in checkbox and doesn’t put in the reasons, there will be no info sent to HTML input element and database. - **Explain the differences between select, checkbox, radio, textarea with regard to how we get the input values.** All of them are HTML attributes that collecting information from users. **Select** : offers a drop down and asks users to select their ansers. **Checkbox** : click on buttons to show their options (multiple answers allowed) radio : the user click to select one of the options **Textarea** : the user type their answer in the blank and click save button Each time those events happened, the js function is called. - **What is the importance of the name attribute, especially for radio buttons?i** Name is a HTML attribute. The JS function need to refer back to the radio buttons elements with the `name="whichDrink"` and to pass the value to the document.querySelectorAll() function. - **Explain the significance of e, banana, bananaEvent, and event.** **How are they the same and how are they different?** - **Try tinkering with some of these functions to produce some different looking, behaving results in the results pane. Explain what you tinkered with and what the results were.**

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully