Giter VIP home page Giter VIP logo

train-fem_rock-paper-scissors's Introduction

Frontend Mentor - Rock, Paper, Scissors solution

This is a solution to the Rock, Paper, Scissors challenge on Frontend Mentor. Frontend Mentor challenges help you improve your coding skills by building realistic projects.

Table of contents

Overview

The challenge

Users should be able to:

  • View the optimal layout for the game depending on their device's screen size
  • Play Rock, Paper, Scissors against the computer
  • Maintain the state of the score after refreshing the browser

Screenshot

home page selection stage computer selection winner stage

Links

My process

Built with

  • Semantic HTML5 markup
  • CSS custom properties
  • Flexbox
  • CSS Grid
  • Mobile-first workflow
  • A11y & aria Standards
  • BEM
  • Sass
  • Gsap

What I learned

This project was built with the aim of experimenting with using gsap to do all the project animations, And try to program a solid code that is easy to modify and improve in the future in order to facilitate the addition of new features to the game

  • BEM naming system
<div class="hero__item--rock linear-gradient hero__item"></div>
  • linear gradient with a one util class
.linear-gradient {
	--deg: 180deg;
	--grad2-deg: 100%;
	--grad1-deg: 0%;
	--grad2-clr: ;
	--grad1-clr: ;
	background: var(--grad1-clr);
	background: linear-gradient(
		var(--deg),
		var(--grad1-clr) var(--grad1-deg),
		var(--grad2-clr) var(--grad2-deg)
	);
}
.hero__item--rock.linear-gradient {
	--grad2-clr: var(--clr-red-800);
	--grad1-clr: var(--clr-red-700);
	box-shadow: inset 0px -8px 0 var(--rock-shadow), 0px 0px 20px 10px hsl(0deg
					0% 0% / 20%);
}
  • Easy to modify container with css variables
.Container {
	--container-width: 90%;
	height: 100%;
	width: var(--container-width, 90%);
	margin-inline: auto;
}
.main-header {
	.Container {
		--container-width: 75%;
	}
}
  • a to click button to use with an element that dose not look like a button but act like one
.toClickButton {
	user-select: none;
	overflow: hidden;
	cursor: pointer;
	text-decoration: none;
	border: none;
	border-radius: var(--border-radius);
}
  • using an object to contain all variables
let header = {
	body: document.querySelector(".main-header"),
	score: {
		button: document.querySelector(".score__button"),
		value: document.querySelector("#scoreValue"),
	},
};
  • get a random number between two numbers
function housePicked() {
	let rand = Math.floor(Math.random() * Object.keys(game.items).length);
	return game.items[rand];
}
let house = housePicked();
  • a function that select a distinct element from a set of elements, and then apply something different to it than is applied to the rest of the elements
function setSpecialThings(
	specialThings,
	fatherSons,
	specialThingsFunction,
	unSpecialThingsFunction
) {
	let specialThingsArr = Array.isArray(specialThings)
		? specialThings
		: [specialThings];

	let fatherSonsArr = Array.isArray(fatherSons) ? fatherSons : [fatherSons];

	for (let fatherSon = 0; fatherSon < fatherSonsArr.length; fatherSon++) {
		if (specialThingsArr.length == 1) {
			if (fatherSonsArr[fatherSon] == specialThingsArr[0]) {
				specialThingsFunction(fatherSonsArr[fatherSon]);
			} else if (fatherSonsArr[fatherSon] != specialThingsArr[0]) {
				unSpecialThingsFunction(fatherSonsArr[fatherSon]);
			}
		} else {
			let unSpecialElement = [];
			let match = false;
			for (let i = 0; i < specialThingsArr.length; i++) {
				if (specialThingsArr[i] == fatherSonsArr[fatherSon]) {
					match = true;
					break;
				}
			}
			if (!match) {
				unSpecialElement.push(fatherSonsArr[fatherSon]);
			}
			specialThingsArr.forEach((specialThing) => {
				specialThingsFunction(specialThing);
			});
			unSpecialElement.forEach((unSpecial) => {
				unSpecialThingsFunction(unSpecial);
			});
		}
	}
}

Continued development

  • using the Json file more
  • using React
  • A11y & aria Standards
  • Gsap & gsap ScrollTrigger

Useful resources

Check out my latest previous articles:

Author

train-fem_rock-paper-scissors's People

Contributors

ymhaah avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.