diff --git a/index.html b/index.html index 04f589d..f61ba36 100644 --- a/index.html +++ b/index.html @@ -20,10 +20,10 @@ -
Comments are useful for documentation in a Go file and are ignored by the compiler. There are two types of comments:
//
/*
*/
+ // one line comment /* this comment @@ -63,23 +63,21 @@ been defined. There are four ways to declare and assign a Go variable: Use the var keyword followed by a name and its data type. This variable can be assigned later in the program. For example: - + var fruit string fruit = "apple" - Use the var keyword followed by a name, data type, = and value. - + Use the var keyword followed by a name, data type, = and value. + var fruit string = "apple" - Use the var keyword, followed by a name, = and value. Ignore the data type and let the compiler infer its type. - + Use the var keyword, followed by a name, = and value. Ignore the data type and let the compiler infer its type. + var fruit = "apple" - Skip the var keyword, define a name followed by := and value and let the compiler infer its type. - - + Skip the var keyword, define a name followed by := and value and let the compiler infer its type. + fruit := "apple" - @@ -96,16 +94,14 @@ Strings - A Go string is a data type that stores text or a sequence of characters in any length in double-quoted form. To - concatenate two strings, use the + operator. - - - var firstName string = "Abe" - var lastName string = "Lincoln" - - // prints "Abe Lincoln" - fmt.Println(firstName + " " + lastName) - + A Go string is a data type that stores text or a sequence of characters in any length in double-quoted form. To + concatenate two strings, use the + operator. + + var firstName string = "Abe" + var lastName string = "Lincoln" + + // prints "Abe Lincoln" + fmt.Println(firstName + " " + lastName) @@ -114,21 +110,19 @@ Comparison Operators Go supports the standard comparison operators that compare two values and return a boolean. These include:
// one line comment /* this comment @@ -63,23 +63,21 @@ been defined. There are four ways to declare and assign a Go variable: Use the var keyword followed by a name and its data type. This variable can be assigned later in the program. For example: - + var fruit string fruit = "apple" - Use the var keyword followed by a name, data type, = and value. - + Use the var keyword followed by a name, data type, = and value. + var fruit string = "apple" - Use the var keyword, followed by a name, = and value. Ignore the data type and let the compiler infer its type. - + Use the var keyword, followed by a name, = and value. Ignore the data type and let the compiler infer its type. + var fruit = "apple" - Skip the var keyword, define a name followed by := and value and let the compiler infer its type. - - + Skip the var keyword, define a name followed by := and value and let the compiler infer its type. + fruit := "apple" - @@ -96,16 +94,14 @@ Strings - A Go string is a data type that stores text or a sequence of characters in any length in double-quoted form. To - concatenate two strings, use the + operator. - - - var firstName string = "Abe" - var lastName string = "Lincoln" - - // prints "Abe Lincoln" - fmt.Println(firstName + " " + lastName) - + A Go string is a data type that stores text or a sequence of characters in any length in double-quoted form. To + concatenate two strings, use the + operator. + + var firstName string = "Abe" + var lastName string = "Lincoln" + + // prints "Abe Lincoln" + fmt.Println(firstName + " " + lastName) @@ -114,21 +110,19 @@ Comparison Operators Go supports the standard comparison operators that compare two values and return a boolean. These include:
Use the var keyword followed by a name and its data type. This variable can be assigned later in the program. For example:
var
+ var fruit string fruit = "apple" - Use the var keyword followed by a name, data type, = and value. - + Use the var keyword followed by a name, data type, = and value. + var fruit string = "apple" - Use the var keyword, followed by a name, = and value. Ignore the data type and let the compiler infer its type. - + Use the var keyword, followed by a name, = and value. Ignore the data type and let the compiler infer its type. + var fruit = "apple" - Skip the var keyword, define a name followed by := and value and let the compiler infer its type. - - + Skip the var keyword, define a name followed by := and value and let the compiler infer its type. + fruit := "apple" - @@ -96,16 +94,14 @@ Strings - A Go string is a data type that stores text or a sequence of characters in any length in double-quoted form. To - concatenate two strings, use the + operator. - - - var firstName string = "Abe" - var lastName string = "Lincoln" - - // prints "Abe Lincoln" - fmt.Println(firstName + " " + lastName) - + A Go string is a data type that stores text or a sequence of characters in any length in double-quoted form. To + concatenate two strings, use the + operator. + + var firstName string = "Abe" + var lastName string = "Lincoln" + + // prints "Abe Lincoln" + fmt.Println(firstName + " " + lastName) @@ -114,21 +110,19 @@ Comparison Operators Go supports the standard comparison operators that compare two values and return a boolean. These include:
var fruit string fruit = "apple"
Use the var keyword followed by a name, data type, = and value.
=
+ Use the var keyword followed by a name, data type, = and value. + var fruit string = "apple" - Use the var keyword, followed by a name, = and value. Ignore the data type and let the compiler infer its type. - + Use the var keyword, followed by a name, = and value. Ignore the data type and let the compiler infer its type. + var fruit = "apple" - Skip the var keyword, define a name followed by := and value and let the compiler infer its type. - - + Skip the var keyword, define a name followed by := and value and let the compiler infer its type. + fruit := "apple" - @@ -96,16 +94,14 @@ Strings - A Go string is a data type that stores text or a sequence of characters in any length in double-quoted form. To - concatenate two strings, use the + operator. - - - var firstName string = "Abe" - var lastName string = "Lincoln" - - // prints "Abe Lincoln" - fmt.Println(firstName + " " + lastName) - + A Go string is a data type that stores text or a sequence of characters in any length in double-quoted form. To + concatenate two strings, use the + operator. + + var firstName string = "Abe" + var lastName string = "Lincoln" + + // prints "Abe Lincoln" + fmt.Println(firstName + " " + lastName) @@ -114,21 +110,19 @@ Comparison Operators Go supports the standard comparison operators that compare two values and return a boolean. These include:
var fruit string = "apple"
Use the var keyword, followed by a name, = and value. Ignore the data type and let the compiler infer its type.
+ Use the var keyword, followed by a name, = and value. Ignore the data type and let the compiler infer its type. + var fruit = "apple" - Skip the var keyword, define a name followed by := and value and let the compiler infer its type. - - + Skip the var keyword, define a name followed by := and value and let the compiler infer its type. + fruit := "apple" - @@ -96,16 +94,14 @@ Strings - A Go string is a data type that stores text or a sequence of characters in any length in double-quoted form. To - concatenate two strings, use the + operator. - - - var firstName string = "Abe" - var lastName string = "Lincoln" - - // prints "Abe Lincoln" - fmt.Println(firstName + " " + lastName) - + A Go string is a data type that stores text or a sequence of characters in any length in double-quoted form. To + concatenate two strings, use the + operator. + + var firstName string = "Abe" + var lastName string = "Lincoln" + + // prints "Abe Lincoln" + fmt.Println(firstName + " " + lastName) @@ -114,21 +110,19 @@ Comparison Operators Go supports the standard comparison operators that compare two values and return a boolean. These include:
var fruit = "apple"
Skip the var keyword, define a name followed by := and value and let the compiler infer its type.
:=
- + Skip the var keyword, define a name followed by := and value and let the compiler infer its type. + fruit := "apple" -
+ Skip the var keyword, define a name followed by := and value and let the compiler infer its type. + fruit := "apple" -
fruit := "apple" -
A Go string is a data type that stores text or a sequence of characters in any length in double-quoted form. To - concatenate two strings, use the + operator.
string
+
- - var firstName string = "Abe" - var lastName string = "Lincoln" - - // prints "Abe Lincoln" - fmt.Println(firstName + " " + lastName) - + A Go string is a data type that stores text or a sequence of characters in any length in double-quoted form. To + concatenate two strings, use the + operator. + + var firstName string = "Abe" + var lastName string = "Lincoln" + + // prints "Abe Lincoln" + fmt.Println(firstName + " " + lastName)
- var firstName string = "Abe" - var lastName string = "Lincoln" - - // prints "Abe Lincoln" - fmt.Println(firstName + " " + lastName) -
A Go string is a data type that stores text or a sequence of characters in any length in double-quoted form. To + concatenate two strings, use the + operator.
+ var firstName string = "Abe" + var lastName string = "Lincoln" + + // prints "Abe Lincoln" + fmt.Println(firstName + " " + lastName)
Go supports the standard comparison operators that compare two values and return a boolean. These include:
==
!=
<
>
<=
>=
- - same := 3 == 3 - // evaluates to true - notsame := "ABC" != "abc" - // evaluates to true - lessthan := 5 <= -5 // evaluates to false - + + same := 3 == 3 + // evaluates to true + notsame := "ABC" != "abc" + // evaluates to true + lessthan := 5 <= -5 // evaluates to false Logical Operators In addition to comparison operators, Go also supports logical operators which evaluate boolean values and return a @@ -138,80 +132,69 @@ Logical Operators
- same := 3 == 3 - // evaluates to true - notsame := "ABC" != "abc" - // evaluates to true - lessthan := 5 <= -5 // evaluates to false -
+ same := 3 == 3 + // evaluates to true + notsame := "ABC" != "abc" + // evaluates to true + lessthan := 5 <= -5 // evaluates to false
In addition to comparison operators, Go also supports logical operators which evaluate boolean values and return a @@ -138,80 +132,69 @@
||
true
!
- - answer := true && false - // returns false - answer = true || false - // returns true - answer = !false - // returns true - + + answer := true && false + // returns false + answer = true || false + // returns true + answer = !false + // returns true Statements If Statement - A Go if statement evaluates a condition and executes a statement block enclosed in curly braces {..} if the evaluation - returns true. The condition may be optionally enclosed inside a pair of parentheses (...). - - - if (healthy) { + A Go if statement evaluates a condition and executes a statement block enclosed in curly braces {..} if the evaluation + returns true. The condition may be optionally enclosed inside a pair of parentheses (...). + + if (healthy) { fmt.Println("Work.") - } - if sick { + } + if sick { fmt.Println("Stay home.") - } - + } Else Statement A Go else statement can succeed an if or if else-if statement block and its code executed if the conditions in the preceding if or if else-if statements evaluate to false. - - sick := false - if sick { + sick := false + if sick { fmt.Println("Call the doctor.") - } else { + } else { fmt.Println("Enjoy your day.") - } - + } Else If Statement The Go else if statement provides an additional condition to evaluate besides the first if conditional. It can only appear after the if statement and before an else statement if it exists. For example: - - if (temperature < 60) { - fmt.Println("Put on a jacket.") - } else if (temperature>= 60 && temperature < 75) { - fmt.Println("Put on a light sweater.") - } else { - fmt.Println("Wear summer clothes.") - } - + if (temperature < 60) { + fmt.Println("Put on a jacket.") + } else if (temperature>= 60 && temperature < 75) { + fmt.Println("Put on a light sweater.") + } else { + fmt.Println("Wear summer clothes.") + } Switch Statement - The Go switch statement can be used as an alternative to a set of if followed by else if statements. The switch + The Go switch statement can be used as an alternative to a set of if followed by else if statements. The switch statement compares the expression inside a condition with a set of values encapsulated in cases. The code inside a matched case value is executed and the switch block terminates. A default case without a value can be appended to the last case and its code executed if no prior match is found. - - day := "Tuesday" - switch day { - case "Monday": - fmt.Println("Monday is magnificent.") - case "Tuesday": - fmt.Println("Tuesday is terrific.") - case "Wednesday": - fmt.Println("Wednesday is wacky.") - default: - fmt.Println("We survived.") - } - - + day := "Tuesday" + switch day { + case "Monday": + fmt.Println("Monday is magnificent.") + case "Tuesday": + fmt.Println("Tuesday is terrific.") + case "Wednesday": + fmt.Println("Wednesday is wacky.") + default: + fmt.Println("We survived.") + } @@ -220,18 +203,16 @@ Switch Statement When a Go function parameter is passed by value, it means only a copy of the value is accessed and manipulated inside the function. The original value of the variable that is passed as an argument to the function remains intact. - - func makeMeOlder(age int) { + func makeMeOlder(age int) { age += 5 - } - - func main() { + } + + func main() { myAge := 10 makeMeOlder(myAge) fmt.Println(myAge) // myAge is still 10 - } - + } @@ -240,24 +221,6 @@ Switch Statement All the documentation in this page is from Code Academy. - + \ No newline at end of file diff --git a/script.js b/script.js new file mode 100644 index 0000000..597ce39 --- /dev/null +++ b/script.js @@ -0,0 +1,56 @@ +const symbolBtn = document.querySelector('.material-symbols-outlined') +const darkmodeBtn = document.querySelector('#darkmode-btn') +const body = document.body +const nav = document.getElementById('navbar') +const link = document.getElementsByTagName('a') + +darkmodeBtn.addEventListener('click', () => { + if (body.classList.contains('light-mode')) { + changeToDark() + } else { + changeToLight() + } +}) + +function changeToDark(){ + body.classList.remove('light-mode') + body.classList.add('dark-mode') + + nav.style.color = 'white' + nav.style.backgroundColor = 'black' + nav.style.borderColor = 'white' + + for (let i = 0, len = link.length; i < len; i++) { + link[i].style.color = 'white' + link[i].style.backgroundColor = 'black' + link[i].style.borderColor = 'white' + } + + // Dark mode button + symbolBtn.innerHTML = 'light_mode' + symbolBtn.style.color = 'yellow' + darkmodeBtn.style.backgroundColor = 'blue' + darkmodeBtn.title = "Change to light mode" +} + +function changeToLight(){ + body.classList.remove('dark-mode') + body.classList.add('light-mode') + + + nav.style.color = 'black' + nav.style.backgroundColor = 'white' + nav.style.borderColor = 'black' + + for (let i = 0, len = link.length; i < len; i++) { + link[i].style.color = 'black' + link[i].style.backgroundColor = 'white' + link[i].style.borderColor = 'white' + } + + // Dark mode button + symbolBtn.innerHTML = 'dark_mode' + symbolBtn.style.color = 'gray' + darkmodeBtn.style.backgroundColor = 'black' + darkmodeBtn.title = "Change to dark mode" +} \ No newline at end of file diff --git a/style.css b/style.css index be62afa..d4382ed 100644 --- a/style.css +++ b/style.css @@ -1,10 +1,4 @@ /* Global */ -:root { - --linkColor: #0c1c3a; - --txtColor: #000; - --bgColor: #fff; -} - * { box-sizing: border-box; margin: 0; @@ -16,25 +10,37 @@ html { } a { - text-decoration: none; - color: var(--linkColor); + color: black; + background-color: white; +} + +/* Color Mode */ +.light-mode { + color: #000; + background-color: #fff; +} + +.dark-mode { + color: #fff; + background-color: #000; } -#darkmode_btn { +#darkmode-btn { position: absolute; - top: 20px; - right: 20px; + top: 10px; + right: 10px; padding: 10px; border: none; border-radius: 50%; - background-color: var(#e1e4ea); + cursor: pointer; + background-color: black; } .material-symbols-outlined { transform: scale(1.5); - color: var(black); + color: gray; font-variation-settings: - 'FILL' 0, + 'FILL' 1, 'wght' 400, 'GRAD' 0, 'opsz' 25 @@ -43,8 +49,8 @@ a { /* Nav */ #navbar { width: 100%; + min-width: 300px; max-height: 500px; - background-color: var(--bgColor); padding: 0px 10px; } @@ -53,6 +59,7 @@ a { display: block; padding: 15px; font-size: 1.3rem; + text-decoration: none; border-bottom: 1px solid black; } @@ -95,21 +102,24 @@ li { } p { + line-height: 1.4rem; padding: 10px 0; } /* Code */ + pre, code { font-family: 'Roboto Mono', monospace; - background-color: var(--bgColor); + color: black; + background-color: whitesmoke; + border-radius: 5px; } pre { white-space: pre-line; - padding: 5px 0 5px 30px; - border-radius: 5px; margin-bottom: 10px; + padding: 5px; } @media (min-width: 1200px) { @@ -136,6 +146,7 @@ pre { } .nav-link { + color: black; font-size: 1.5rem; }
- answer := true && false - // returns false - answer = true || false - // returns true - answer = !false - // returns true -
+ answer := true && false + // returns false + answer = true || false + // returns true + answer = !false + // returns true
A Go if statement evaluates a condition and executes a statement block enclosed in curly braces {..} if the evaluation - returns true. The condition may be optionally enclosed inside a pair of parentheses (...).
if
{..}
(...)
- - if (healthy) { + A Go if statement evaluates a condition and executes a statement block enclosed in curly braces {..} if the evaluation + returns true. The condition may be optionally enclosed inside a pair of parentheses (...). + + if (healthy) { fmt.Println("Work.") - } - if sick { + } + if sick { fmt.Println("Stay home.") - } - + }
- if (healthy) { + A Go if statement evaluates a condition and executes a statement block enclosed in curly braces {..} if the evaluation + returns true. The condition may be optionally enclosed inside a pair of parentheses (...). + + if (healthy) { fmt.Println("Work.") - } - if sick { + } + if sick { fmt.Println("Stay home.") - } -
A Go if statement evaluates a condition and executes a statement block enclosed in curly braces {..} if the evaluation + returns true. The condition may be optionally enclosed inside a pair of parentheses (...).
+ if (healthy) { fmt.Println("Work.") - } - if sick { + } + if sick { fmt.Println("Stay home.") - } -
A Go else statement can succeed an if or if else-if statement block and its code executed if the conditions in the preceding if or if else-if statements evaluate to false.
else
if else-if
false
- - sick := false - if sick { + sick := false + if sick { fmt.Println("Call the doctor.") - } else { + } else { fmt.Println("Enjoy your day.") - } - + }
- sick := false - if sick { + sick := false + if sick { fmt.Println("Call the doctor.") - } else { + } else { fmt.Println("Enjoy your day.") - } -
The Go else if statement provides an additional condition to evaluate besides the first if conditional. It can only appear after the if statement and before an else statement if it exists. For example:
else if
- - if (temperature < 60) { - fmt.Println("Put on a jacket.") - } else if (temperature>= 60 && temperature < 75) { - fmt.Println("Put on a light sweater.") - } else { - fmt.Println("Wear summer clothes.") - } - + if (temperature < 60) { + fmt.Println("Put on a jacket.") + } else if (temperature>= 60 && temperature < 75) { + fmt.Println("Put on a light sweater.") + } else { + fmt.Println("Wear summer clothes.") + }
- if (temperature < 60) { - fmt.Println("Put on a jacket.") - } else if (temperature>= 60 && temperature < 75) { - fmt.Println("Put on a light sweater.") - } else { - fmt.Println("Wear summer clothes.") - } -
The Go switch statement can be used as an alternative to a set of if followed by else if statements. The switch +
switch
The Go switch statement can be used as an alternative to a set of if followed by else if statements. The switch statement compares the expression inside a condition with a set of values encapsulated in cases. The code inside a matched case value is executed and the switch block terminates. A default case without a value can be appended to the last case and its code executed if no prior match is found.
case
default
- - day := "Tuesday" - switch day { - case "Monday": - fmt.Println("Monday is magnificent.") - case "Tuesday": - fmt.Println("Tuesday is terrific.") - case "Wednesday": - fmt.Println("Wednesday is wacky.") - default: - fmt.Println("We survived.") - } - - + day := "Tuesday" + switch day { + case "Monday": + fmt.Println("Monday is magnificent.") + case "Tuesday": + fmt.Println("Tuesday is terrific.") + case "Wednesday": + fmt.Println("Wednesday is wacky.") + default: + fmt.Println("We survived.") + }
- day := "Tuesday" - switch day { - case "Monday": - fmt.Println("Monday is magnificent.") - case "Tuesday": - fmt.Println("Tuesday is terrific.") - case "Wednesday": - fmt.Println("Wednesday is wacky.") - default: - fmt.Println("We survived.") - } - -
When a Go function parameter is passed by value, it means only a copy of the value is accessed and manipulated inside the function. The original value of the variable that is passed as an argument to the function remains intact.
- - func makeMeOlder(age int) { + func makeMeOlder(age int) { age += 5 - } - - func main() { + } + + func main() { myAge := 10 makeMeOlder(myAge) fmt.Println(myAge) // myAge is still 10 - } - + }
- func makeMeOlder(age int) { + func makeMeOlder(age int) { age += 5 - } - - func main() { + } + + func main() { myAge := 10 makeMeOlder(myAge) fmt.Println(myAge) // myAge is still 10 - } -
All the documentation in this page is from Code Academy.