Skip to content
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
74 changes: 74 additions & 0 deletions 01week/datatypes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
'Use Strict'

// Write a JavaScript program to display the current day and time

let now = new Date();
console.log("the current date and time is: " + now);

let myButton = document.getElementById("theTime");
myButton.addEventListener('click', function(){
myButton.innerText = now.toString();
});

// Write a JavaScript program to convert a number to a string.

const theNumber = 5;
const theString = theNumber.toString();

console.log(theNumber.toString());
console.log(theNumber);

// Write a JavaScript program to convert a string to the number.

const theOtherString = "4.5";
const theOtherNumber = parseInt(theOtherString, 10);
console.log(theOtherNumber);

// Write a JavaScript program that takes in different datatypes and prints out whether they are a:
// Boolean
const myBool = true;
console.log(typeof myBool);
// Null
const myNull = null;
console.log(typeof myNull);
// Undefined
const myUndefined = undefined;
console.log(typeof myUndefined);
// Number
const myNumber = 3;
console.log(typeof myNumber);
// NaNconst
const myNaN = NaN;
console.log(typeof myNaN);

// String
const myString = 'Joe';
console.log(typeof myString);

// Write a JavaScript program that adds 2 numbers together.
const mySum = 2+3;
console.log(mySum);

let displaySum = document.getElementById("Sum");
displaySum.innerText = mySum.toString();
// Write a JavaScript program that runs only when 2 things are true.
const num1 = true;
const num2 = true;

if(num1&&num2){
console.log('both are true');
};
// Write a JavaScript program that runs when 1 of 2 things are true.
const num3 = true;
const num4 = false;

if(num3||num4){
console.log('one is true');
};
// Write a JavaScript program that runs when both things are not true.
const num5 = false;
const num6 = false;

if(!num5&&!num6){
console.log('both are false');
};
3 changes: 3 additions & 0 deletions 01week/helloworld.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'use strict'

console.log("Hello World");
17 changes: 17 additions & 0 deletions 01week/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<!-- <div id="display-element"></div>
<button onclick="displayDate()">Click Me</button> -->
<h1>The current date and time is<button id='theTime'> click for date</button>
</h1>
<br>
<h1>The sum of 2 and 3 is: <span id='Sum'></span>
</h1>
</body>
<script src="datatypes.js"></script>
</html>