Rock Paper Scissors

A simple game using switch, if/else, and user input.

package main

import "fmt"

func main() {
	computer := "rock"

	var player string
	fmt.Print("Choose (rock/paper/scissors): ")
	fmt.Scan(&player)

	fmt.Printf("You: %s | Computer: %s\n", player, computer)

	if player == computer {
		fmt.Println("It's a tie!")
	} else {
		switch player {
		case "rock":
			if computer == "scissors" {
				fmt.Println("You win!")
			} else {
				fmt.Println("You lose!")
			}
		case "paper":
			if computer == "rock" {
				fmt.Println("You win!")
			} else {
				fmt.Println("You lose!")
			}
		case "scissors":
			if computer == "paper" {
				fmt.Println("You win!")
			} else {
				fmt.Println("You lose!")
			}
		default:
			fmt.Println("Invalid choice.")
		}
	}
}

💻 Run locally

Copy the code above and run it on your machine

© 2026 ByteLearn.dev. Free courses for developers. · Privacy