forked from mouredev/roadmap-retos-programacion
-
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
Gerardo Medellin
committed
Jan 22, 2024
1 parent
1446acc
commit 58fb4ff
Showing
1 changed file
with
84 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,84 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"strconv" | ||
) | ||
|
||
var global = "Soy una variable global" | ||
|
||
func main() { | ||
|
||
Sayhi() | ||
|
||
fmt.Println(Outputname("Gera")) | ||
|
||
fmt.Println(Twoparams(1, 2)) | ||
|
||
fmt.Println(Doubleamounts(2)) | ||
|
||
fmt.Println(Comporobartipo(2)) | ||
|
||
Scope() | ||
|
||
extra := Extra("Fizz", "Buzz") | ||
|
||
fmt.Println("El numero de veces que se imprimieron numeros fue: ", extra) | ||
|
||
} | ||
|
||
// Funcion basica, sin parametros ni retorno | ||
func Sayhi() { | ||
fmt.Println("Hola mundo") | ||
} | ||
|
||
// Funcion con un parametro con retorno | ||
func Outputname(name string) string { | ||
//return a string with the name injected | ||
return "Hola usuario " + name | ||
} | ||
|
||
// Funcion con parametros y retorno | ||
func Twoparams(param1 int, param2 int) int { | ||
return param1 + param2 | ||
} | ||
|
||
// Funcion adentro de otra funcion | ||
func Doubleamounts(amount1 int) int { | ||
//funcion anonima | ||
Multiplyby := func (number int) int { | ||
return number * 2 | ||
} | ||
return Multiplyby(amount1) | ||
} | ||
|
||
// Funcion ya creada en el lenguaje | ||
func Comporobartipo(param int) string { | ||
return `El valor de param es ` + strconv.Itoa(param) + ` y el tipo es ` + fmt.Sprintf("%T", param) | ||
} | ||
|
||
// Funcion para probar el scope de las variables | ||
func Scope() { | ||
//variable local | ||
var local = "Soy una variable local" | ||
fmt.Println(local) | ||
fmt.Println(global) | ||
} | ||
|
||
// Dificultad extra | ||
func Extra(str1 string, str2 string) int { | ||
count := 0 | ||
for i := 1; i <= 100; i++ { | ||
if i % 3 == 0 && i % 5 == 0 { | ||
fmt.Println(str1 + str2) | ||
} else if i % 3 == 0 { | ||
fmt.Println(str1) | ||
} else if i % 5 == 0 { | ||
fmt.Println(str2) | ||
} else { | ||
fmt.Println(i) | ||
count++ | ||
} | ||
} | ||
return count | ||
} |