Skip to content

Solved arrays #90

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

Open
wants to merge 51 commits into
base: task-arrays
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
2b5f14c
Require Hello World in the document
acbart Jan 31, 2022
a7dee05
Rename text.Test.tsx to text.test.tsx
acbart Jan 31, 2022
3e381f3
Include the task info
acbart Jan 31, 2022
fee03d3
Merge branch 'task-first-branch' of https://github.com/UD-CISC275-S22…
acbart Jan 31, 2022
e6b1dab
Allow one or more instances of the Hello World text
acbart Feb 3, 2022
646e7c8
Merge pull request #1 from frontend-fun/update-branches
acbart Aug 20, 2024
db36697
Merge pull request #2 from frontend-fun/update-branches
acbart Aug 20, 2024
c9aba7f
Merge pull request #3 from frontend-fun/update-branches
acbart Aug 20, 2024
268363c
Merge pull request #4 from frontend-fun/update-branches
acbart Aug 20, 2024
0483016
Merge pull request #5 from frontend-fun/update-branches
acbart Aug 20, 2024
a68506a
Merge pull request #6 from frontend-fun/update-branches
acbart Aug 20, 2024
a36ba0c
Merge pull request #7 from frontend-fun/update-branches
acbart Aug 20, 2024
bbc42c0
Merge pull request #8 from frontend-fun/update-branches
acbart Aug 20, 2024
214e285
Merge pull request #9 from frontend-fun/update-branches
acbart Aug 20, 2024
7fe9ca3
Require Hello World in the document
acbart Jan 31, 2022
b8b8878
Include the task info
acbart Jan 31, 2022
fbdebde
Rename text.Test.tsx to text.test.tsx
acbart Jan 31, 2022
2f0146c
Allow one or more instances of the Hello World text
acbart Feb 3, 2022
a6acb43
Merge branch 'task-first-branch' of https://github.com/frontend-fun/t…
acbart Aug 24, 2024
ac36b32
First set of tests
acbart Jan 30, 2022
d04739d
Some logging tests
acbart Jan 30, 2022
b26100f
More html tests
acbart Jan 30, 2022
3bf4550
Fix the image test
acbart Jan 30, 2022
8dff2b6
Updated CSS tests, left a note about additional tests
acbart Jan 31, 2022
b66d4de
See previous commit message
acbart Jan 31, 2022
0a24364
Add in new css test
acbart Aug 24, 2024
4d43d7a
Add in points
acbart Aug 24, 2024
83c4461
Basic functions tests and stubs
acbart Jan 30, 2022
a486530
Fix test organization
acbart Jan 30, 2022
9722564
Fix issue in fahrenheit conversion
acbart Jan 30, 2022
bd06d5d
Move around some of the functions
acbart Feb 3, 2022
4cd1900
Explain what the actual functions require you to do
acbart Feb 3, 2022
cf1d21a
Update formatting
acbart Aug 24, 2024
e11693a
Add in points
acbart Aug 24, 2024
2e9ba49
update readme and names
greglnelson Sep 6, 2024
80f1cf6
Update HtmlCss.test.tsx
greglnelson Sep 17, 2024
6e31832
Update deploy.yml
TSchotter Feb 11, 2025
41b9e93
Update deploy.yml
TSchotter Feb 11, 2025
566436c
revert changes
TSchotter Feb 11, 2025
2ee502d
Update deploy.yml
TSchotter Feb 11, 2025
26b9f36
Update deploy.yml
TSchotter Feb 11, 2025
b1583a1
Merge pull request #55 from TSchotter/TSchotter-patch-1
TSchotter Feb 11, 2025
9432bbe
Added name to App
Zombo3 Feb 18, 2025
bad2b80
Merge remote-tracking branch 'upstream/task-first-branch' into solved…
Zombo3 Mar 4, 2025
7900568
update package lock
Zombo3 Mar 4, 2025
762306d
Added hello wolrd
Zombo3 Mar 4, 2025
e0c3f30
Merge remote-tracking branch 'upstream/task-html-css' into solved-htm…
Zombo3 Mar 4, 2025
20c2f46
editing for chapter 3
Zombo3 Mar 4, 2025
6e03976
Merge remote-tracking branch 'upstream/task-functions' into solved-fu…
Zombo3 Mar 4, 2025
7d8beae
Updated functions, App.tsx, and styling
Zombo3 Mar 5, 2025
73a7003
Merge remote-tracking branch 'upstream/task-arrays' into solved-arrays
Zombo3 Mar 5, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
with:
fetch-depth: 0
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- id: get-repo-values
Expand All @@ -39,7 +39,7 @@ jobs:
url=https://$(echo "${{github.repository}}" | sed "s/\//.github.io\//")
echo "url=$url" >> $GITHUB_OUTPUT
- name: Update package.json homepage
uses: jossef/action-set-json-field@v1
uses: jossef/action-set-json-field@v2.1
with:
file: package.json
field: homepage
Expand Down Expand Up @@ -134,14 +134,14 @@ jobs:
# echo "</body></html>" >> ./dist/index.html
# Deploy
- name: Setup Pages
uses: actions/configure-pages@v3
uses: actions/configure-pages@v5
if: ${{ !cancelled() }}
- name: Upload artifact
uses: actions/upload-pages-artifact@v2
uses: actions/upload-pages-artifact@v3
if: ${{ !cancelled() }}
with:
path: "dist/"
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v2
uses: actions/deploy-pages@v4
if: ${{ !cancelled() }}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

Hello! This repository has been pre-configured with eslint, prettier, and a github actions workflow to automatically lint and format your code on every push. It'll also deploy your site for you.

You'll complete programming problems by merging in upstream branches. Check out the textbook for more information: <https://frontend-fun.github.io/react-hooks-typescript-tome/>
You'll complete programming problems by merging in upstream branches. Check out the textbook for more information: <https://greglnelson.github.io/react-hooks-typescript-tome/>
143 changes: 77 additions & 66 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"@testing-library/user-event": "^13.5.0",
"@types/jest": "^27.5.2",
"@types/node": "^16.18.105",
"bootstrap": "^5.3.3",
"react": "^18.3.1",
"react-bootstrap": "^2.10.4",
"react-dom": "^18.3.1",
Expand Down
5 changes: 5 additions & 0 deletions public/tasks/task-first-branch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Task - First Branch

Version: 0.0.1

Pass a short test to have certain text on the page.
5 changes: 5 additions & 0 deletions public/tasks/task-functions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Task - Functions

Version: 0.0.1

Implement a bunch of functions that work on primitives.
5 changes: 5 additions & 0 deletions public/tasks/task-html-css.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Task - HTML/CSS

Version: 0.0.1

Add in some HTML and CSS, including a fancy looking button.
2 changes: 1 addition & 1 deletion src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

.App-header {
width: 100%;
background-color: #282c34;
background-color: lightblue;
min-height: 40vh;
display: flex;
flex-direction: column;
Expand Down
2 changes: 1 addition & 1 deletion src/App.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ import App from "./App";

test("renders the course name somewhere", () => {
render(<App />);
const linkElement = screen.getByText(/CISC275/i);
const linkElement = screen.getByText(/COS420/i);
expect(linkElement).toBeInTheDocument();
});
31 changes: 29 additions & 2 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,42 @@
import React from "react";
import "./App.css";
import "bootstrap/dist/css/bootstrap.min.css";


function App(): React.JSX.Element {
return (
<div className="App">
<header className="App-header">
UD CISC275 with React Hooks and TypeScript
<h1></h1>UM COS420 with React Hooks and TypeScript<h1></h1>
</header>
<img
src="https://images.fineartamerica.com/images/artworkimages/medium/3/letter-s-graffiti-alphabet-s-typography-blue-letter-s-bubble-letter-s-elsayed-atta-transparent.png"
alt="Placeholder Image"
/>
<ul>
<li>React Hooks</li>
<li>TypeScript</li>
<li>Component Styling</li>
</ul>
<button
className="btn btn-primary"
onClick={() => {
console.log("Hello World!");
}}
>
Log Hello World
</button>
<div
style={{
width: "100px",
height: "50px",
backgroundColor: "red",
}}
></div>

<p>
Edit <code>src/App.tsx</code> and save. This page will
automatically reload.
automatically reload. sany dagher, Hello World
</p>
</div>
);
Expand Down
83 changes: 83 additions & 0 deletions src/HtmlCss.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import React from "react";
import { render, screen } from "@testing-library/react";
import App from "./App";
import userEvent from "@testing-library/user-event";

describe("Some HTML Elements are added.", () => {
test("(2 pts) There is a heading", () => {
render(<App />);
const heading = screen.getAllByRole("heading");
expect(heading[0]).toBeInTheDocument();
});

test("(2 pts) There is an image with alt text", () => {
render(<App />);
const image = screen.getByRole("img");
expect(image).toBeInTheDocument();
expect(image).toHaveAttribute("alt");
});

test("(2 pts) There is a list with at least three elements", () => {
render(<App />);
const list = screen.getByRole("list");
expect(list).toBeInTheDocument();
expect(list.children.length).toBeGreaterThanOrEqual(3);
});
});

describe("(2 pts) Some basic CSS is added.", () => {
test("The background color of the header area is different", () => {
render(<App />);
const banner = screen.getByRole("banner");
expect(banner).not.toHaveStyle({
"background-color": "rgb(40, 44, 52)",
});
});
});

describe("(2 pts) Some Bootstrap Elements are added", () => {
test("There is one bootstrap button with the text 'Log Hello World'", () => {
render(<App />);
const button = screen.getByRole("button", { name: /Log Hello World/i });
expect(button).toBeInTheDocument();
expect(button).toHaveClass("btn");
expect(button).toHaveClass("btn-primary");
});

test("(2 pts) Not clicking the bootstrap button does not logs 'Hello World!'", () => {
const consoleSpy = jest.spyOn(console, "log");
render(<App />);
expect(consoleSpy).not.toHaveBeenCalledWith("Hello World!");
});

test("(2 pts) Clicking the bootstrap button logs 'Hello World!'", () => {
const consoleSpy = jest.spyOn(console, "log");
render(<App />);
const button = screen.getByRole("button", { name: /Log Hello World/i });
userEvent.click(button);
expect(consoleSpy).toHaveBeenCalledWith("Hello World!");
});
});

describe("Some additional CSS was added", () => {
test("(2 pts) checks if any element has a background color of red", () => {
const { container } = render(<App />);
// Get all elements in the rendered container
const elements = container.querySelectorAll("*");

// Check if any element has a background color of red
let foundRedBackground = false;

elements.forEach((element) => {
const style = getComputedStyle(element);
if (
style.backgroundColor === "red" ||
style.backgroundColor === "rgb(255, 0, 0)"
) {
foundRedBackground = true;
}
});

expect(foundRedBackground).toBe(true);
});
});
59 changes: 59 additions & 0 deletions src/functions.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import {
add3,
fahrenheitToCelius,
shout,
isQuestion,
convertYesNo,
} from "./functions";

describe("Testing the basic functions", () => {
test("(3 pts) Testing the fahrenheitToCelius function", () => {
expect(fahrenheitToCelius(32)).toBe(0);
expect(fahrenheitToCelius(-40)).toBe(-40);
expect(fahrenheitToCelius(-22)).toBe(-30);
expect(fahrenheitToCelius(14)).toBe(-10);
expect(fahrenheitToCelius(68)).toBe(20);
expect(fahrenheitToCelius(86)).toBe(30);
expect(fahrenheitToCelius(212)).toBe(100);
});

test("(3 pts) Testing the add3 function", () => {
expect(add3(1, 2, 3)).toBe(6);
expect(add3(9, 7, 4)).toBe(20);
expect(add3(6, -3, 9)).toBe(15);
expect(add3(10, 1, -9)).toBe(11);
expect(add3(-9, -100, -4)).toBe(0);
expect(add3(-1, -1, 1)).toBe(1);
});

test("(3 pts) Testing the shout function", () => {
expect(shout("Hello")).toBe("HELLO!");
expect(shout("What?")).toBe("WHAT?!");
expect(shout("oHo")).toBe("OHO!");
expect(shout("AHHHH!!!")).toBe("AHHHH!!!!");
expect(shout("")).toBe("!");
expect(shout("Please go outside")).toBe("PLEASE GO OUTSIDE!");
});

test("(3 pts) Testing the isQuestion function", () => {
expect(isQuestion("Is this a question?")).toBe(true);
expect(isQuestion("Who are you?")).toBe(true);
expect(isQuestion("WHAT ARE YOU !?")).toBe(true);
expect(isQuestion("WHAT IS THIS?!")).toBe(false);
expect(isQuestion("OH GOD!")).toBe(false);
expect(isQuestion("Oh nevermind, it's fine.")).toBe(false);
expect(isQuestion("")).toBe(false);
});

test("(3 pts) Testing the convertYesNo function", () => {
expect(convertYesNo("yes")).toBe(true);
expect(convertYesNo("YES")).toBe(true);
expect(convertYesNo("NO")).toBe(false);
expect(convertYesNo("no")).toBe(false);
expect(convertYesNo("Apple")).toBe(null);
expect(convertYesNo("Bananas")).toBe(null);
expect(convertYesNo("Nope")).toBe(null);
expect(convertYesNo("Yesterday")).toBe(null);
expect(convertYesNo("Maybe")).toBe(null);
});
});
48 changes: 48 additions & 0 deletions src/functions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/**
* Consumes a single temperature in Fahrenheit (a number) and converts to Celsius
* using this formula:
* C = (F - 32) * 5/9
*/
export function fahrenheitToCelius(temperature: number): number {
return ((temperature - 32) * 5) / 9;
}

/**
* Consumes three numbers and produces their sum. BUT you should only add a number
* if the number is greater than zero.
*/
export function add3(first: number, second: number, third: number): number {
return ((first > 0 ? first : 0) + (second > 0 ? second : 0) + (third > 0 ? third : 0)
);;
}

/**
* Consumes a string and produces the same string in UPPERCASE and with an exclamation
* mark added to the end.
*/
export function shout(message: string): string {
return message.toUpperCase() + "!";
}

/**
* Consumes a string (a message) and returns a boolean if the string ends in a question
* mark. Do not use an `if` statement in solving this question.
*/
export function isQuestion(message: string): boolean {
return message.endsWith("?");
}

/**
* Consumes a word (a string) and returns either `true`, `false`, or `null`. If the string
* is "yes" (upper or lower case), then return `true`. If the string is "no" (again, either
* upper or lower case), then return `false`. Otherwise, return `null`.
*/
export function convertYesNo(word: string): boolean | null {
if(word === "yes" || word === "YES"){
return true};
if(word === "no" || word === "NO"){
return false
};

return null;
}
9 changes: 9 additions & 0 deletions src/text.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import React from "react";
import { render, screen } from "@testing-library/react";
import App from "./App";

test("renders the text 'Hello World' somewhere", () => {
render(<App />);
const texts = screen.getAllByText(/Hello World/);
expect(texts.length).toBeGreaterThanOrEqual(1);
});