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

C15501723 wks 2 #203

Open
wants to merge 6 commits 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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion worksheets/1-basic-html-css-dom-api/README

This file was deleted.

Empty file.
Empty file.
Empty file.
7 changes: 7 additions & 0 deletions worksheets/Lab 2/GithubInterface.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
p {
float:left;
padding: 0px 0px 50px 0px;
width:60%;
border: 1px solid gray;

}
63 changes: 63 additions & 0 deletions worksheets/Lab 2/GithubInterface.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<!DOCTYPE html>
<html>
<head>
<style>
#content
{
float:left;
padding: 0px 0px 20px 10px;
width:40%;
border: 1px solid gray;

}

p
{

padding: 0px 0px 30px 10px;

border: 1px solid gray;
}

.topnav {
overflow: hidden;
background-color: #e9e9e9;
width: 40%;
}

</style>
</head>
<body>

<div class="topnav">
<input id="userSearch" placeholder="Search..">
<button type="button" onclick="myFunction()">Submit</button>
</div>





<h1>User Profile</h1>

<section id="content">

<img id="myImg" width="50%" height="20%">


<p id="name"></p>
<p id="username"></p>
<p id="email"></p>
<p id="location"></p>
<p id="NumberofGist"></p>
<p id="repo_name"></p>

</section>




<script src = "GithubInterface.js"></script>

</body>
</html>
37 changes: 37 additions & 0 deletions worksheets/Lab 2/GithubInterface.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
function myFunction() {
var str1 = "https://api.github.com/users/";
var str2 = document.getElementById("userSearch").value;;
var res = str1.concat(str2);

// POST adds a random id to the object sent
fetch(res, {
method: 'Get',
headers: {
"Content-type": "application/json; charset=UTF-8"
}
})
.then(promise => promise.json())
.then((data) => {


document.getElementById("myImg").src = data.avatar_url;
document.getElementById("name").innerHTML = data.name;
document.getElementById("username").innerHTML = data.login;
document.getElementById("email").innerHTML = data.email;
document.getElementById("location").innerHTML = data.location;
document.getElementById("NumberofGists").innerHTML = data.public_gists;
/*
var repos = "/repos";
var res = res.concat(repos);

document.getElementById("repo_name").innerHTML = data.name;
*/
});





}


68 changes: 68 additions & 0 deletions worksheets/Lab 2/Problem_set_1.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<!DOCTYPE html>
<html>
<head>
<style>

button{
background: lightGray;
width: 20%;
font-size: 20px;
border-radius: 20px;
margin-left: 15px;
margin-top: 10px;
}

body{
position: relative;
width: 400px;
border: 5px solid black;
border-radius: 10px;
margin: 0px auto;
padding: 20px 20px 50px 20px;
}

input[type = text] {
position: relative;
display: block;
width: 90%;
margin: 0px auto;
font-size: 20px;
padding: 10px;
}
</style>
</head>
<body>
<br>
<input type="text" name = "display" id = "display" disabled/>

<button type="button" onclick ="display.value += '('">(</button>
<button type="button" onclick ="display.value += ')'">)</button>
<button type="button" >+_</button>
<button type="button" onclick ="display.value += '/'">/</button>
<br/>

<button type="button" onclick ="display.value += '7'">7</button>
<button type="button" onclick ="display.value += '8'">8</button>
<button type="button" onclick ="display.value += '9'">9</button>
<button type="button" onclick ="display.value += '*'">X</button>
</br>

<button type="button" onclick ="display.value += '4'">4</button>
<button type="button" onclick ="display.value += '5'">5</button>
<button type="button" onclick ="display.value += '6'">6</button>
<button type="button" onclick ="display.value += '-'">-</button>
</br>

<button type="button" onclick ="display.value += '1'">1</button>
<button type="button" onclick ="display.value += '2'">2</button>
<button type="button" onclick ="display.value += '3'">3</button>
<button type="button" onclick ="display.value += '+'">+</button>
</br>

<button type="button" onclick ="display.value += '0'">0</button>
<button type="button" onclick ="display.value += '.'">.</button>
<button type="button" >C</button>
<button type="button" onclick = "display.value = eval(display.value)">=</button>
</br>
</body>
</html>
13 changes: 13 additions & 0 deletions worksheets/Lab 2/Problem_set_2.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html>
<body>

<script src="Problem_set_2.js">


</script>


</body>

</html>
24 changes: 24 additions & 0 deletions worksheets/Lab 2/Problem_set_2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// POST adds a random id to the object sent
fetch('https://jsonplaceholder.typicode.com/users', {
method: 'Get',
headers: {
"Content-type": "application/json; charset=UTF-8"
}
})
.then(promise => promise.json())
.then((data) => {

data.map((user) => {

//part 1
console.log(user.name , user.address.city, user.address.zipcode);

//part 2
if(user.address.zipcode[0] == 5 || user.address.zipcode[0] == 2)
{
console.log(user.name , user.address.city, user.address.zipcode);
}

});

});
13 changes: 13 additions & 0 deletions worksheets/Lab 2/Problem_set_2_part2.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html>
<body>

<script src="Problem_set_2_part2.js">


</script>


</body>

</html>
27 changes: 27 additions & 0 deletions worksheets/Lab 2/Problem_set_2_part2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// POST adds a random id to the object sent
fetch('https://jsonplaceholder.typicode.com/posts', {
method: 'Get',
headers: {
"Content-type": "application/json; charset=UTF-8"
}
})
.then(promise => promise.json())
.then((data) => {

//part 3
data.map((posts) => {

var str = posts.title;
var wordCount = str.match(/(\w+)/g).length;

if(wordCount < 6)
{
console.log(posts);
}




});

});
13 changes: 13 additions & 0 deletions worksheets/Lab 2/Problem_set_part3.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html>
<body>

<script src="Problem_set_part3.js">


</script>


</body>

</html>
40 changes: 40 additions & 0 deletions worksheets/Lab 2/Problem_set_part3.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// POST adds a random id to the object sent
fetch('https://jsonplaceholder.typicode.com/posts', {
method: 'Get',
headers: {
"Content-type": "application/json; charset=UTF-8"
}
})
.then(promise => promise.json())
.then((data) =>
{


data.map((posts) =>
{
//part 3
var pattern = /\w+/g,
string = posts.body
matchedWords = string.match( pattern );

var counts = matchedWords.reduce(
function ( stats, word )
{
if ( stats.hasOwnProperty( word ) )
{
stats[ word ] = stats[ word ] + 1;
}
else
{
stats[ word ] = 1;
}
return stats;

}, {} );

console.log( counts );


});

});