Skip to content

Instantly share code, notes, and snippets.

@datduyng
Created May 24, 2020 23:30
Show Gist options
  • Save datduyng/8f03bd3fe9d40390133f925f07ef0c13 to your computer and use it in GitHub Desktop.
Save datduyng/8f03bd3fe9d40390133f925f07ef0c13 to your computer and use it in GitHub Desktop.
google page
<html>
<header>
</header>
<!-- commenting -->
<body>
<h1>Google</h1>
<input id="user-input" type="text"/>
<button onclick="triggerMe()"> search</button>
<h4>answer</h4>
<p id="answer"></p>
<script>
console.log('from script tag');
</script>
<script src="./index.js"></script>
</body>
</html>
/*
cd <PATH> - change directory <PATH> : ../ | ./
ls - list files/dir under a path
*/
// cout << "Hello world" << endl; in c.
console.log('hello world'); //in js
// console.log('1 + 1 is', (1+1));
let answer = 2;
function calculateOnePlusOne() {
return answer; //2;
}
console.log('1 + 1 is',calculateOnePlusOne());
function triggerMe() {
console.log('you just click me');
console.log('document object', document);
let user_input = document.getElementById('user-input');
let user_input_val = user_input.value; // is a string.
if (user_input_val == 'hello world') {
console.log('welcome to earth');
// user_input.value = 'welcome to earth';
document.getElementById('answer').innerHTML = "welcome to earth";
} else if (user_input_val == 'what is your name') {
document.getElementById('answer').innerHTML = "Michael";
} else if (user_input_val == '1+1') {
document.getElementById('answer').innerHTML = "2";
}
}
function calculate() {
//get user input
let user_input = document.getElementById('user-input');
let user_input_val = user_input.value; // is a string.
//TODO: do logic.
//write answer.
document.getElementById('answer').innerHTML = "TODO: ANSWER"
}
/*
1. change textarea to input
2. create "search" button
3. create a simple calcultor.
int main() {
int c = 1;
}
cout << c << endl;
'c'
char c = 'a'; // type char.
int num = 1; // type int.
string s = "abc";
char[] cs = {"a", "b", "c"};
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment