Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

first commit #210

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Binary file added .DS_Store
Binary file not shown.
27 changes: 9 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,13 @@
# ↔️ Week08 Bootcamp2019a Project: Server Side Palindrome Checker
# Palindrome

### Goal: Create a simple web application that uses the fs and http modules to validate if a string is a palindrome server side.
## How it's made
JS, Node.JS

### How to submit your code for review:
JS: The client side calls the API in the local server using the Fetch API. It will grab the user's input, the reversed of the user's input, and compare whether these two values are a palindrome. The results will print to the DOM.

- Fork and clone this repo
- Create a new branch called answer
- Checkout answer branch
- Push to your fork
- Issue a pull request
- Your pull request description should contain the following:
- (1 to 5 no 3) I completed the challenge
- (1 to 5 no 3) I feel good about my code
- Anything specific on which you want feedback!
Node.JS: Node.js was used to import several Node.js modules: http, fs, url, and queryStrings (from the user). Then I defined the server, extract the requested page's pathname, and parses query parameters. When a user submits a string, the following tasks are performed on the server side. Variables are created to hold the future object that will be returned as part of the API response. The user's input is reversed and checked by following these steps: the string is converted into an array using the 'split()' method, reversed using the 'reverse()' method, and finally, the reversed array is converted back into a string using the 'join()' method.

Example:
```
I completed the challenge: 5
I feel good about my code: 4
I'm not sure if my constructors are setup cleanly...
```
The server compares the original user input with the reversed version of the input to determine if they match. If they do match, the API returns a boolean value of 'true' to indicate that the input is a palindrome; otherwise, it returns 'false' to signify that the input is not a palindrome.

## Lessons Learned
I learned the quintessential difference between accessing user inputs between the DOM's browser API and the server side. Since document.query selector is no longer relevant on the server side, I had to understand how to grab the user's input a different way, by whether a key named 'palindrome' exists in the params object and, if it does, to assign the corresponding value to a variable named 'name'. That value is the user's input.
12 changes: 12 additions & 0 deletions api.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<link rel="stylesheet" href="/css/style.css">
</head>
<body>
<h1>API Loading</h1>
<script type="text/javascript" src="/js/main.js"></script>
</body>
</html>
3 changes: 3 additions & 0 deletions css/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
h1{
color: red;
}
5 changes: 5 additions & 0 deletions data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
name: "leon",
status: "Boss Man",
currentOccupation: "Baller"
}
17 changes: 17 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<link rel="stylesheet" href="/css/style.css">
</head>
<body>
<h1>Is it a palindrome?</h1>
<input id="userInput" type="text" name="" placeholder="Enter Name">
<button id="clickMe" type="button" name="button">Click Me</button>
<h2 id="name"></h2>
<h2 id="palindrome"></h2>
<h2 id="result"></h2>
<script type="text/javascript" src="/js/main.js"></script>
</body>
</html>
45 changes: 45 additions & 0 deletions js/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
document.querySelector('#clickMe').addEventListener('click', makeReq)

function makeReq(){
const userInput = document.querySelector("#userInput").value;
fetch(`/api?palindrome=${userInput}`)
.then(response => response.json())
.then((data) => {
console.log(data);
document.querySelector("#name").textContent = `You entered ${data.name}`
document.querySelector("#palindrome").textContent = `The reverse is ${data.reversedName}`
document.querySelector("#result").textContent = `Is it a palindrome? ${data.result}`
});
}

// document.getElementById("clickMe").onclick = makeReq;
//
// function makeReq(){
//
// var userName = document.getElementById("userName").value;
//
// var request = new XMLHttpRequest();
// request.open('GET', '/api?student='+userName, true);
//
// request.onload = function() {
// console.log("works")
// if (request.status >= 200 && request.status < 400) {
// // Success!
// var data = JSON.parse(request.responseText);
// console.log(data)
// document.getElementById("personName").innerHTML = data.name
// document.getElementById("personStatus").innerHTML = data.status
// document.getElementById("personOccupation").innerHTML = data.currentOccupation
//
// } else {
// // We reached our target server, but it returned an error
//
// }
// };
//
// request.onerror = function() {
// // There was a connection error of some sort
// };
//
// request.send();
// }
Binary file added node_modules/figlet/.DS_Store
Binary file not shown.
13 changes: 13 additions & 0 deletions node_modules/figlet/.jshintrc

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/figlet/.npmignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions node_modules/figlet/.travis.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 42 additions & 0 deletions node_modules/figlet/Gruntfile.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions node_modules/figlet/LICENSE.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading