-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit bdf6180
Showing
5 changed files
with
262 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Document</title> | ||
<link rel="stylesheet" href="style.css"> | ||
</head> | ||
<body> | ||
<h1>MY CALCULATOR</h1> | ||
<div class="container" id="container"> | ||
<input type="text" id="display" value="" disabled> | ||
<div id="buttons"> | ||
<button class="number">1</button> | ||
<button class="number">2</button> | ||
<button class="number">3</button> | ||
<button class="operator">+</button> | ||
<button class="number">4</button> | ||
<button class="number">5</button> | ||
<button class="number">6</button> | ||
<button class="operator">-</button> | ||
<button class="number">7</button> | ||
<button class="number">8</button> | ||
<button class="number">9</button> | ||
<button class="operator">x</button> | ||
<button class="operator">C</button> | ||
<button class="number">0</button> | ||
<button class="equal">=</button> | ||
<button class="operator">/</button> | ||
</div> | ||
</div> | ||
|
||
<script src="javascript.js"></script> | ||
|
||
|
||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
const display=document.getElementById("display"); | ||
const buttons=document.getElementById("buttons"); | ||
|
||
|
||
buttons.addEventListener("click",(event)=>{ | ||
// console.log(event.target.innerHTML); | ||
// console.log(event.target.classList.contains("number")); | ||
let Target=event.target; | ||
if (Target.innerHTML==="C") | ||
|
||
{ | ||
display.value=""; | ||
} | ||
else if(Target.classList.contains("number")) | ||
{ | ||
display.value+=Target.innerHTML; | ||
} | ||
else if(Target.classList.contains("operator")) | ||
{ | ||
const str=display.value; | ||
const lastChar=str[str.length-1]; | ||
if ( | ||
lastChar === "+" || | ||
lastChar === "-" || | ||
lastChar === "x" || | ||
lastChar === "/" | ||
){ | ||
display.value=str.slice(0,-1)+Target.innerHTML; //eliminates repeated element: | ||
} | ||
else{ | ||
|
||
display.value+=Target.innerHTML; | ||
}} | ||
else if (Target.classList.contains("equal")){ | ||
if (display.value.length!==0){ | ||
try{ | ||
const result=eval(display.value); | ||
display.value=result; | ||
}catch(error){ | ||
display.value="This is wrong expression"; | ||
}} | ||
else{ | ||
display.value=""; | ||
}} | ||
|
||
} | ||
) ; | ||
|
||
// const str=display.value; | ||
// const lastChar=str[str.length-1]; | ||
// const operator=["+","/","-","*"]; | ||
// for(let i=0;i<operator.length;i++){ | ||
// if (lastChar===operator[i]) | ||
// } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
// let fact=(array)=>{ | ||
// arr=[]; | ||
// for(i=0;i<array.length;i++){ | ||
// let k=1; | ||
// for (j=1;j<=array[i];j++){ | ||
// k*=j | ||
// }arr.push(k); | ||
// } | ||
// console.log(arr);} | ||
// fact([2,4,0,5,6]); | ||
|
||
|
||
// let max=(array)=>{ | ||
// arr=[]; | ||
// for(i=0;i<array.length;i++){ | ||
// let k=1; | ||
// for (j=1;j<=array[i];j++){ | ||
// k*=j | ||
// }arr.push(k); | ||
// } | ||
// console.log(arr);} | ||
// max([2,4,0,5,6]); | ||
|
||
// let maxNumber=(arr)=>{ | ||
// k=Map(Math.max(arr)); | ||
// return k; | ||
// } | ||
// console.log(maxNumber([2,4,0,5,6])); | ||
|
||
|
||
|
||
|
||
// input=["apple","banana","grapes"]; | ||
// const result=input.map((str)=>{ | ||
// return (str.length); | ||
// }); | ||
// console.log(result); | ||
|
||
|
||
|
||
//filter | ||
|
||
// const number = [1, -2, 3, -4, 5, 6, 7,-8, 9, 10]; | ||
|
||
// const evenNumbers = number.filter((num) => num<0); | ||
// console.log(evenNumbers); // Output: [2, 4, 6, 8, 10] | ||
|
||
|
||
|
||
//reduce | ||
// const numbers = [1, 2, 3, 4, 5]; | ||
|
||
// const product= numbers.reduce((accumulator, currentValue) => accumulator*currentValue, 1); | ||
// console.log(product); | ||
|
||
// const numb = [1, 2, 3, 4, 5]; | ||
|
||
// const min= numb.reduce((accumulator, currentValue) => accumulator>currentValue, 99999); | ||
// console.log(min); | ||
|
||
|
||
|
||
//Objects:--> | ||
// const students = [ | ||
// { name: "Alice", age: 20 }, | ||
// { name: "Bob", age: 17 }, | ||
// { name: "Charlie", age: 19 }, | ||
// { name: "David", age: 16 }, | ||
// { name: "Eve", age: 21 } | ||
// ]; | ||
// // Q7 : Write a JavaScript function that takes an array of objects representing students, | ||
// // filters out the students whose age is less than 18, and returns an array with the names of the remaining students | ||
|
||
// const ages=students.filter((student)=>student.age<18) | ||
// .map(student.name); | ||
|
||
// const string=["name","cla","dd","dndj"]; | ||
// const result=string.map((str)=>{ | ||
// str.filter(str.length>3); | ||
|
||
// }); | ||
// console.log(result); | ||
|
||
|
||
// const strings = ["name", "cla", "dd", "dndj"]; | ||
// const result = strings.filter((str) => str.length > 3).map(str).uppercase(); | ||
// console.log(result); | ||
|
||
//concatenate using reduce, | ||
// const array=["the", "man", "is", "playing"]; | ||
// const result=array.reduce((acc,curr) => acc+" "+curr); | ||
// console.log(result) | ||
|
||
const books = [ | ||
{ title: "The Great Gatsby", rating: 4.5 }, | ||
{ title: "To Kill a Mockingbird", rating: 4.8 }, | ||
{ title: "1984", rating: 3.9 }, | ||
{ title: "Pride and Prejudice", rating: 4.2 }, | ||
{ title: "The Catcher in the Rye", rating: 3.7 } | ||
]; | ||
// Q10 : Write a JavaScript function that | ||
// takes an array of objects representing books, filters out the books with a rating less than 4, | ||
// maps the remaining books to their titles, and returns an array of book titles. | ||
|
||
const obj=books.filter(book=>book.rating<4).map(obj=>obj.title); | ||
console.log(obj); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
*{ | ||
padding: 0; | ||
margin: 0; | ||
box-sizing: border-box; | ||
} | ||
body{ | ||
|
||
text-align: center; | ||
/* justify-content: center; */ | ||
background-image: linear-gradient(to right,black,#799F0C,blue,#799F0C,blue); | ||
/* background-image: linear-gradient( to right, #051937, #002768, #273199, #5f30c6, #9f12eb ); */ | ||
} | ||
|
||
.container{ | ||
height:19.5rem; | ||
width:15rem; | ||
background-color: bisque; | ||
margin-left: 42.5%; | ||
/* text-align: center; */ | ||
/* justify-content: center; */ | ||
margin-top: 2%; | ||
border-radius: 10px; | ||
border:4px solid blue; | ||
box-shadow:0 3px 4px 0 pink; | ||
} | ||
input{ | ||
margin-top: 4px; | ||
height: 4rem; | ||
width:14rem; | ||
border-radius: 4px; | ||
background-color: white; | ||
box-shadow:0 3px 4px 0 gray; | ||
} | ||
button | ||
{ margin-top: 4px; | ||
width: 52px; | ||
height: 53px; | ||
background-color:white; | ||
border-radius: 10px; | ||
box-shadow:0 3px 4px 0 gray; | ||
|
||
} | ||
button:hover | ||
{ | ||
color:white; | ||
background-color: purple; | ||
} | ||
|
||
h1{ | ||
margin-top: 10%; | ||
color: aqua; | ||
text-shadow:3px 0 cornsilk; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
onst students = [ | ||
// { name: "Alice", age: 20 }, | ||
// { name: "Bob", age: 17 }, | ||
// { name: "Charlie", age: 19 }, | ||
// { name: "David", age: 16 }, | ||
// { name: "Eve", age: 21 } | ||
// ]; | ||
// // Q7 : Write a JavaScript function that takes an array of objects representing students, | ||
// // filters out the students whose age is less than 18, and returns an array with the names of the remaining students | ||
|
||
// const ages=students.filter((student)=>student.age<18) | ||
// .map(student.name); |