-
-
Notifications
You must be signed in to change notification settings - Fork 42
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
Manchester | Zabihollah Namazi | Module-Data-Flows | challenges | unit-testing | passing-tests #125
base: main
Are you sure you want to change the base?
Changes from 5 commits
44c5916
6c01e2f
fe83add
a459074
4797cfa
99f462f
d7ffec7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,28 @@ | ||
function sales(carsSold) {} | ||
let carsSold = [ | ||
{ make: "Ford", model: "Fiesta", colour: "Red", price: 5999 }, | ||
{ make: "Land Rover", model: "Defender", colour: "Muddy", price: 12000 }, | ||
{ make: "Toyota", model: "Prius", colour: "Silver", price: 6500 }, | ||
{ make: "Honda", model: "Civic", colour: "Yellow", price: 8000 }, | ||
{ make: "Ford", model: "Fiesta", colour: "Red", price: 15000 }, | ||
{ make: "Land Rover", model: "Discovery", colour: "Blue", price: 9000 }, | ||
{ make: "Ford", model: "Fiesta", colour: "Green", price: 2000 }, | ||
]; | ||
|
||
function sales(carsSold) { | ||
let totals = { | ||
Ford: 0, | ||
Honda: 0, | ||
"Land Rover": 0, | ||
Toyota: 0, | ||
}; | ||
for(let key in totals){ | ||
for(let obj in carsSold){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would suggest to rename There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. car would be better in my opinion |
||
if (key == carsSold[obj].make){ | ||
totals[key] += carsSold[obj].price; | ||
} | ||
} | ||
} | ||
return totals; | ||
} | ||
sales(carsSold); | ||
module.exports = sales; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,3 +22,4 @@ test("Car sales", function () { | |
|
||
expect(output).toEqual(totals); | ||
}); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,16 @@ | ||
// the input is an array of numbers and strings | ||
// return the average of all the numbers | ||
// be sure to exclude the strings | ||
|
||
function average(numbers) {} | ||
|
||
let numbers = [4, "-", 8, 11, "hello", "57", 0, 2, "hi", 22]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can't agree that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. updated |
||
function average(numbers) { | ||
let numCount = 0; | ||
for (let item in numbers){ | ||
if (typeof(numbers[item]) == "number"){ | ||
numCount += 1; | ||
} | ||
} | ||
console.log(numCount); | ||
return numCount; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks to me that you are returning counter (how many numbers you have found in the given array). I think your task is to return average. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed it |
||
} | ||
average(numbers); | ||
module.exports = average; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<link rel="stylesheet" href="style.css"> | ||
<title>XKCD Comic Viewer</title> | ||
<script src="script.js" defer></script> | ||
</head> | ||
<body> | ||
<!-- <section id="section"></section> --> | ||
|
||
|
||
|
||
|
||
|
||
</body> | ||
</html> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
|
||
let myData; | ||
|
||
async function fetchData() { | ||
try{ | ||
const response = await fetch("https://xkcd.now.sh/?comic=latest") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please, always close your expressions with a semicolon ; |
||
|
||
if (!response.ok) { | ||
throw new Error(`HTTP error! Status: ${response.status}`); | ||
} | ||
|
||
myData = await response.json() | ||
//console.log(`${JSON.stringify(myData)} this is api`) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please, don't leave commented out code in your final work. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this commit is a mistake |
||
let section = document.body; | ||
const image = document.createElement("img"); | ||
image.src = myData.img; | ||
image.alt = myData.alt; | ||
section.appendChild(image); | ||
} | ||
catch(error) { | ||
console.error("an error happened", error.message); | ||
alert("Something went wrong. Please try again later."); | ||
} | ||
|
||
} | ||
|
||
fetchData() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
img{ | ||
width: 500px; | ||
height: 500px; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you think of a better name for
key
? Hint: think what it will contain and how you are going to use its value (you will compare it tomake
from array).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think makeCar would be better