Giter VIP home page Giter VIP logo

lab-word-counter's Introduction

LAB: Word Counter

In this lab, you will be using your HTML, CSS and some basic JS skills to create and style a word counter.

Get Started

  • Navigate to your ~/workspace/foundations/inclass directory
$ git clone {YOUR REPO LINK}
$ cd LAB-word-counter

Setup the Project

  • Create a setup branch
$ git checkout -b setup
  • Create the following files:
    • Create an index.html file
    • Create a main.css file
    • Create a main.js file
  • Connect the JS file and your CSS file to your HTML
    • If you need help with this, do a google search for how to do it

Push your work to Github

$ git add -A
$ git commit -m "WRITE A DETAILED MESSAGE"
$ git push origin setup
  • Create a Pull Request (PR) on Github
  • Merge the PR into the main branch
  • Go back to VS Code and checkout the main branch git checkout main
  • Pull the updated code: git pull origin main

Get the Code

  • Create an add-code branch
$ git checkout -b add-code

Place the following code in the index.html file

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Word Counter</title>
</head>
<body>
  <h1>Word Counter</h1>
  <button id="bg-switch">Dark Mode</button>
  <div id="error" class="error"></div>
  <form>
    <textarea placeholder="Place your words here..."></textarea>
    <button type="submit">Submit</button>
    <button type="reset">Clear</button>
  </form>
  <div id="word-count"></div>

</body>
</html>

Place the following code in the main.js file

console.log("Connected!")
// YOU WILL MODIFY THIS FUNCTION TO GET THE PROGRAM TO WORK
const wordCounter = (value) => {
  // Type into the input and press submit, you will see the value you entered in your console
  console.log(value);

  if (value) {
    // COMPLETE THE LOGIC 
    wordCount.innerHTML = `Word Count: 0`; 
  } else {
    // if the value is empty, set the error message value to "Please input text"
    error.innerHTML = ""; // UPDATE THIS
  }
}

// OPTIONAL CHALLENGE
const toggleMode = (btnText) => {
  // complete the function
}

// ************************************************ //
// **** DO NOT MODIFY THE CODE BELOW THIS LINE **** //
// ************************************************ //

// These are query selectors. We will focus on them later in the course
const textarea = document.querySelector("textarea");
const form = document.querySelector("form");
const error = document.querySelector("#error");
const wordCount = document.querySelector("#word-count");
const toggleButton = document.querySelector("#bg-switch");

// These are event listeners. We will focus on them later in the course
form.addEventListener("submit", (event) => {
  event.preventDefault(); // the default behavior of a form is to reload the page, we do not want that so we want to prevent that behavior
  error.innerHTML = ""; // clear out the innerHTML on submit
  wordCount.innerHTML = ""; // clear out the innerHTML on submit
  const value = textarea.value; // grab the value of the text area on submit
  wordCounter(value); // call the function and pass it the value
});

form.addEventListener("reset", () => {
  error.innerHTML = ""; // on reset, clear the innderHTML
  wordCount.innerHTML = ""; // on reset, clear the innderHTML
});

toggleButton.addEventListener("click", (event) => {
  toggleMode(event.target.innerHTML);
});

Connect the files

  • Connect the JS file to the HTML file
  • Connect the CSS file to the HTML file

Test the code

  • Start your server: run hs -o or http-server -o to start your server.
  • Check your console. The message "Connected!" should be seen.

Push your work to Github

$ git add -A
$ git commit -m "WRITE A DETAILED MESSAGE"
$ git push origin add-code
  • Create a Pull Request (PR) on Github
  • Merge the PR into the main branch
  • Go back to VS Code and checkout the main branch git checkout main
  • Pull the updated code: git pull origin main

Get Organized

  • Go to your repo and click on the Issues Tab taking note of the things that need to be completed for the lab

Screen Shot 2022-03-19 at 1 42 02 AM

  • Create a project named "Word Counter" and choose "Basic Kanban"

word-counter

  • Move issue tickets into the project and work through them each

drag

Styling

Screen Shot 2022-03-18 at 10 47 46 PM

Screen Shot 2022-03-18 at 10 47 57 PM

Screen Shot 2022-03-18 at 10 48 26 PM

Challenge

Add Bootstrap to your HTML elements like buttons and the form.

NOTE: Do not remove the ID attributes from the HTML. When you copy over the Bootstrap component, make sure to add the attribute to it.

lab-word-counter's People

Contributors

mmccullough1997 avatar

Watchers

 avatar

lab-word-counter's Issues

Challenge 2: CSS - Style the application

Using the example image, style the application based on the following Acceptance Criteria (AC)

  • Set the body width to 90% and center it on the page
  • Center the Title
  • make the textarea width 100% and give it 20 rows
  • make the placeholder text color blue
  • make the font size 1.5em
  • make the font-family Arial, Helvetica, sans-serif
  • style the button:
    • background green
    • font color white
    • give it some padding
    • make the font size 1.5em

Challenge 3: Add Bootstrap

  • Add bootstrap to the project by connecting all the files in the index.html
  • Change the textarea input with the textarea from Bootstrap
  • Update the buttons with Bootstrap buttons

Challenge 4: OPTIONAL - Let's get JS Crazy!

Based on the example code below the DO NOT MODIFY line, try and create a button that toggles the background between dark and light mode on click.

Change the text on the button when clicked.

Challenge 1: FUNCTIONALITY - Modify the code in the JS file

In the JS code you copied over, there are comments that tell you what you should work on.

Review the code that is in the project think through how to solve the following issue

There is an issue with the program...it is not showing the accurate amount of words that a user inputs. Modify the wordCounter function to accurately display the amount of words.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.