Showing posts with label Javacript. Show all posts
Showing posts with label Javacript. Show all posts

ROCK PAPER SCISSOR GAME BUILD USING HTML, CSS and Javascript


 This Rock Paper Scissor Game Build Using HTML CSS and Javascript .

Click Here to View the live website

Click Here to view the original source code at github

Below is the Source Code of Above game

<!--------------------------------- HTML CODE ------------------------->

<!DOCTYPE html>

<html lang="en">

<head>

    <link rel="stylesheet" href="style.css">

    <meta charset="UTF-8">

    <meta http-equiv="X-UA-Compatible" content="IE=edge">

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>Rockpaperscissor</title>

</head>

<body>

    <div class="container">

        <button class="game" value="Rock">✊</button>

        <button class="game" value="Paper">✋</button>

        <button class="game" value="Scissors">✌</button>

        <div class="showresult">

        <p id="player-score"></p>

        <p id="hands"></p>

        <p id="result"></p>

        </div>

        <button class="reset games" id="endGameButton">🔴</button>

    </div>

    <script src="javascr.js"></script>

    <footer>Made By Vaibhav Yadav with ❤❤</footer>

</body>

</html>

//                                    Javascript Code 

const totalscore = { computerScore: 0, playerScore: 0}


function getcomputerchoice() {

    const rpschoice = ['Rock','Paper','Scissors']

    const randomnumber = Math.floor( Math.random()*3 )

    return rpschoice[randomnumber]

}

function getResult(playerChoice, computerChoice) {

    let score;

    if( playerChoice == computerChoice){ 

    score = 0

    totalscore['computerScore']+= 0

    }

    else if ( playerChoice == 'Rock' && computerChoice == 'Scissors'){

        score = 1

    }

    else if ( playerChoice == 'Paper' && computerChoice == 'Rock'){

        score = 1

    } else if ( playerChoice == 'Scissors' && computerChoice == 'Paper'){

        score = 1

    }

    else{

       score = -1

       totalscore['computerScore']+= 1

 }

    return score

}

function showresult(score,playerChoice,computerChoice)

{

    const resultdiv = document.getElementById('result')

    const handdiv = document.getElementById('hands')

    const playerscorediv = document.getElementById('player-score')

    if(score == -1 ) {

        resultdiv.innerText = "You Lose"

    }

    else if(score == 0 ){

        resultdiv.innerText = "It's a tie"

    }

    else{

        resultdiv.innerText = "You Win"

    }

    handdiv.innerText = "Computer Choice is: " + computerChoice

    playerscorediv.innerText =  "Your Score is : " + totalscore["playerScore"] + "  Computer Score is : " +totalscore["computerScore"]

    

}

function onClickgames(playerChoice){

    // console.log({playerChoice})

    const computerChoice = getcomputerchoice()

    // console.log({computerChoice})

    const score = getResult(playerChoice, computerChoice)

    totalscore['playerScore'] += score

    // console.log({score})

    // console.log(totalscore) 

    showresult(score,playerChoice,computerChoice)

}

function playGame(){

    const games = document.querySelectorAll('.game')

    // games[0].onclick = () => alert(games[0].value)

    

    games.forEach(game => {

        game.onclick = () => onClickgames(game.value)

    })

}

const endgamebutton = document.getElementById("endGameButton")

endgamebutton.onclick = () =>endgame(totalscore)

function endgame(totalscore)

{

    totalscore['playerScore'] = 0

    totalscore['computerScore'] = 0


    const resultdiv = document.getElementById('result')

    const handdiv = document.getElementById('hands')

    const playerscorediv = document.getElementById('player-score')


    resultdiv.innerText = ''

    handdiv.innerText = ''

    playerscorediv.innerText = ''

}

playGame()

/*                              CSS CODE                    */

body{

    background-color: black;

    margin: 0;

    padding: 0;

    font-weight: bolder;

    font-family: sans-serif;

}

.container{

    border-radius: 4%;

    box-shadow: 10px 10px 50px black;

    padding: 2vh;

    width: 80vh;

    text-align: center;

    background-color: steelblue;

    margin: 20vh auto;

}

.container button{

    background-color: transparent;

    border: none;

    

    margin: 3vh;

}

.game {

    box-shadow: 5px 5px 9px black;

    border-radius: 9%;

    /* background-color: red; */

    font-size: 70px;

    cursor: pointer;

}

.reset{

    

    font-size: 50px;

    margin: 9vh 0 0 31vh;

    width: 20vh;

}

/* .container span:hover { 

    transform: rotate(-40deg);

} */

.showresult{

    padding: 2px;

    border-radius: 9px;

    box-shadow: 5px 5px 13px black;

}

.showresultnone{

    height: 0;

    display: none;

}

.games{

    box-shadow: 5px 5px 9px black;

    border-radius: 9%;

    /* background-color: red; */

    font-size: 70px;

    cursor: pointer;

}

button:active{

    transform: translate(2px, 2px);

}

footer{

    text-align: center;

    background-color: wheat;


Tip Calculator Build Using HTML, CSS and JAVASCRIPT Only

 

This is Tip calculator build using HTML, CSS and Javascript .

Click Here to View the Live website

Click Here to view Original Source Code at github

Given Below is HTML Source Code 

<!DOCTYPE html>

<html lang="en">

<head>

    <link rel="stylesheet" href="tip.css">

    <meta charset="UTF-8">

    <meta http-equiv="X-UA-Compatible" content="IE=edge">

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>Tip Calculator</title>

</head>

<body>

    <div class="container">

    <div class="header">Tip calculator</div>

    <p>Bill Total</p>

    <div class="billtotal">

        <input type="text" id="billTotalInput" placeholder="0.00" onkeyup="calculateBill()"/>

    </div>


    <p>Tip(%)</p>

    <div class="tipinput">

        <input type="text" id="tipInput" placeholder="10" onkeyup="calculateBill()"/>

    </div>

    <div class="bottomcontainer">

    <span class="noofpeople">No. of People <br>

        <span class="buttoncontainer">

        <span class="increase" onclick="increasePeople()"><button>+</button></span>

        <span class="textvalue" id="numberofPeople">1</span>

        <span class="decrease" onclick="decreasePeople()"><button>-</button></span>

        </span>

    </span>


    <span class="totalcontainer">

        <span class="title">Total Per Person </span><br><span class="total">₹</span>

        <span class="total" id="perPersonTotal">0.00</span>

    </span>

    </div>

</div>

<footer><H2>Made By Vaibhav Yadav with ❤❤</H2></footer>


<script src="tip.js"></script>

</body>

</html>

                                                             CSS Code is Given Here:

body{

    font-family: sans-serif;

    margin: 0;

    padding: 0;

    font-weight: bolder;

}

.container{

    width: 60vh;

    border-radius: 8px;

    box-shadow: 10px 10px 30px black;

    margin: 20vh auto;

    background-color: steelblue;

    padding: 5vh;

}

.container input{

    box-sizing: border-box;

    padding: 0.4vh;

    border-radius: 6px;

    width: 100%;

}

input[type=text]:focus{

    outline: none;

    background-color: lightcyan;

}

footer {

    text-align: center;

}

.header{

    text-align: center;

    font-size: 25px;

    font-family: 'Times New Roman', Times, serif;

    padding: 2vh;

}

.textvalue{

    padding: 1vh;

}

.tipinput{

    margin: 0;

    padding: 0;

}

.totalcontainer{

    margin: 2vh auto;

    text-align: center;

    

}

.total{

    font-family: Arial, Helvetica, sans-serif;

    font-size: 20px;

    color: black;

}

.noofpeople{

    margin: 2vh auto;

}

.bottomcontainer{

    display: flex;

    

    

}

                                                    This is Javascript File

const billInput = document.getElementById('billTotalInput')

const tipInput = document.getElementById('tipInput')

const numberofPeopleDiv = document.getElementById('numberofPeople')

const perPersonTotalDiv = document.getElementById('perPersonTotal')


let numberofPeople = Number(numberofPeopleDiv.innerText)


const calculateBill = () => {

    

    

    


    const bill = Number(billInput.value)

    

    const tipPercent  = Number(tipInput.value)/100


    const tipAmount = bill*tipPercent


    const total = tipAmount + bill

    const perPersonTotal = total/numberofPeople

    perPersonTotalDiv.innerText = perPersonTotal.toFixed(2)

}

const increasePeople = () => {

    numberofPeople+=1

    numberofPeopleDiv.innerText = numberofPeople

    if(numberofPeople>1){

        numberofPeopleDiv.style.color = "black";

    }

    calculateBill()

}


const decreasePeople = ( ) => {

    if(numberofPeople<=1){

        numberofPeopleDiv.style.color = "red";

        alert("Invalid, Input")

        return

    }

    numberofPeople -=1

    numberofPeopleDiv.innerText = numberofPeople

    calculateBill( )

}


Operator Overloading in C++

#include<iostream> using namespace std; class Complex { private: int real, imag; public: Complex(int r = 0, int i = 0){       re...