From 21c7b16d565590f70967036875d73750430fc9a1 Mon Sep 17 00:00:00 2001 From: rajamouli Date: Sat, 13 Sep 2025 23:02:16 +0530 Subject: [PATCH 1/3] completed task-01 --- 1-js-basics/1-data-types/assignment.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/1-js-basics/1-data-types/assignment.md b/1-js-basics/1-data-types/assignment.md index 55c3b06..4b9b100 100644 --- a/1-js-basics/1-data-types/assignment.md +++ b/1-js-basics/1-data-types/assignment.md @@ -1,5 +1,5 @@ -# Data Types Practice - -## Instructions - -Imagine you are building a shopping cart. Write some documentation on the data types that you would need to complete your shopping experience. How did you arrive at your choices? +- Strings: To store text-based information such as product names, categories, and user details. +- Numbers:To handle all quantities, prices, totals, and IDs. +- Boolean:To represent true/false conditions in the cart. +- Arrays:To store lists of related items, such as products in the cart. +- Objects:To represent structured data like a single product, user, or order. \ No newline at end of file From 0c15659b03a5042be40517a18352a518f56fc107 Mon Sep 17 00:00:00 2001 From: rajamouli Date: Sat, 13 Sep 2025 23:44:02 +0530 Subject: [PATCH 2/3] 2nd commit --- 1-js-basics/2-functions-methods/assignment.md | 25 +++++++++++++++---- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/1-js-basics/2-functions-methods/assignment.md b/1-js-basics/2-functions-methods/assignment.md index 4621399..24e8c2a 100644 --- a/1-js-basics/2-functions-methods/assignment.md +++ b/1-js-basics/2-functions-methods/assignment.md @@ -1,7 +1,22 @@ -# Fun with Functions +# Challenge +- method is something that belong to an object or a class. It is also defined within a class defination. +while function is something that can be defined any where and used anywhere. A method can only be used to manipulate or something related to it to a class or its objects +# assignment +``` +function funct1(a){ + console.log(a); +} +``` +- or it can be written in the following way -## Instructions +``` +function funct2(a){ + return a; +} +``` +- here is the function with defualt and normal parameters -Create different functions, both functions that return something and functions that don't return anything. - -See if you can create a function that has a mix of parameters and parameters with default values. +``` +function funct3(a=2,b){ + console.log(a+b); +} From 933bd794d5c55704ac4372e19a47986122906b2d Mon Sep 17 00:00:00 2001 From: rajamouli Date: Sun, 14 Sep 2025 10:42:16 +0530 Subject: [PATCH 3/3] 1st one --- 3-typing-game/typing-game/assignment.md | 5 -- 3-typing-game/typing-game/game/index.html | 19 +++++ 3-typing-game/typing-game/game/script.js | 85 +++++++++++++++++++++++ 3-typing-game/typing-game/game/script1.js | 77 ++++++++++++++++++++ 3-typing-game/typing-game/game/style.css | 12 ++++ 5 files changed, 193 insertions(+), 5 deletions(-) create mode 100644 3-typing-game/typing-game/game/index.html create mode 100644 3-typing-game/typing-game/game/script.js create mode 100644 3-typing-game/typing-game/game/script1.js create mode 100644 3-typing-game/typing-game/game/style.css diff --git a/3-typing-game/typing-game/assignment.md b/3-typing-game/typing-game/assignment.md index 0427a27..e69de29 100644 --- a/3-typing-game/typing-game/assignment.md +++ b/3-typing-game/typing-game/assignment.md @@ -1,5 +0,0 @@ -# Create a new keyboard game - -## Instructions - -Create a small game that uses keyboard events to do tasks. It may be a different kind of typing game, or an art type game that paints pixels to the screen on keystrokes. Get creative! Try to implement concepts that you have learnt in this topic. \ No newline at end of file diff --git a/3-typing-game/typing-game/game/index.html b/3-typing-game/typing-game/game/index.html new file mode 100644 index 0000000..06aa586 --- /dev/null +++ b/3-typing-game/typing-game/game/index.html @@ -0,0 +1,19 @@ + + + Typing game + + + +

Typing game!

+

Practice your typing skills with a quote from Sherlock Holmes. Click **start** to begin!

+

+

+
+ + +
+
+

+ + + \ No newline at end of file diff --git a/3-typing-game/typing-game/game/script.js b/3-typing-game/typing-game/game/script.js new file mode 100644 index 0000000..14d5977 --- /dev/null +++ b/3-typing-game/typing-game/game/script.js @@ -0,0 +1,85 @@ +const quotes = [ + 'When you have eliminated the impossible, whatever remains, however improbable, must be the truth.', + 'There is nothing more deceptive than an obvious fact.', + 'I ought to know by this time that when a fact appears to be opposed to a long train of deductions it invariably proves to be capable of bearing some other interpretation.', + 'I never make exceptions. An exception disproves the rule.', + 'What one man can invent another can discover.', + 'Nothing clears up a case so much as stating it to another person.', + 'Education never ends, Watson. It is a series of lessons, with the greatest for the last.', + 'hi' +]; + +let words = []; +let wordIndex = 0; +// the starting time +let startTime = Date.now(); +// page elements +const quoteElement = document.getElementById('quote'); +const messageElement = document.getElementById('message'); +const typedValueElement = document.getElementById('typed-value'); + +// at the end of script.js +document.getElementById('start').addEventListener('click', () => { + // get a quote + const quoteIndex = Math.floor(Math.random() * quotes.length); + const quote = quotes[7]; + // Put the quote into an array of words + words = quote.split(' '); + // reset the word index for tracking + wordIndex = 0; + + // UI updates + // Create an array of span elements so we can set a class + const spanWords = words.map(function(word) { return `${word} `}); + // Convert into string and set as innerHTML on quote display + quoteElement.innerHTML = spanWords.join(''); + // Highlight the first word + quoteElement.childNodes[0].className = 'highlight'; + // Clear any prior messages + messageElement.innerText = ''; + + // Setup the textbox + // Clear the textbox + typedValueElement.value = ''; + // set focus + typedValueElement.focus(); + // set the event handler + + // Start the timer + startTime = new Date().getTime(); + }); + +// at the end of script.js +typedValueElement.addEventListener('input', () => { + // Get the current word + const currentWord = words[wordIndex]; + // get the current value + const typedValue = typedValueElement.value; + + if (typedValue === currentWord && wordIndex === words.length - 1) { + // end of sentence + // Display success + const elapsedTime = new Date().getTime() - startTime; + const message = `CONGRATULATIONS! You finished in ${elapsedTime / 1000} seconds.`; + messageElement.innerText = message; + } else if (typedValue.endsWith(' ') && typedValue.trim() === currentWord) { + // end of word + // clear the typedValueElement for the new word + typedValueElement.value = ''; + // move to the next word + wordIndex++; + // reset the class name for all elements in quote + for (const wordElement of quoteElement.childNodes) { + wordElement.className = ''; + } + // highlight the new word + quoteElement.childNodes[wordIndex].className = 'highlight'; + } else if (currentWord.startsWith(typedValue)) { + // currently correct + // highlight the next word + typedValueElement.className = ''; + } else { + // error state + typedValueElement.className = 'error'; + } + }); \ No newline at end of file diff --git a/3-typing-game/typing-game/game/script1.js b/3-typing-game/typing-game/game/script1.js new file mode 100644 index 0000000..87bdf8a --- /dev/null +++ b/3-typing-game/typing-game/game/script1.js @@ -0,0 +1,77 @@ +const quotes = [ + 'When you have eliminated the impossible, whatever remains, however improbable, must be the truth.', + 'There is nothing more deceptive than an obvious fact.', + 'I ought to know by this time that when a fact appears to be opposed to a long train of deductions it invariably proves to be capable of bearing some other interpretation.', + 'I never make exceptions. An exception disproves the rule.', + 'What one man can invent another can discover.', + 'Nothing clears up a case so much as stating it to another person.', + 'Education never ends, Watson. It is a series of lessons, with the greatest for the last.', + "i" +]; + +let words = []; +let wordIndex = 0; +let startTime = Date.now(); +const quoteElement = document.getElementById('quote'); +const messageElement = document.getElementById('message'); +const typedValueElement = document.getElementById('typed-value'); + + +document.getElementById('start').addEventListener('click', () => { + const quoteIndex = Math.floor(Math.random()*quotes.length); // get a random number and store quote with that index into quote + const quote = quotes[7]; + words = quote.split(' '); + wordIndex = 0; + const spanWords = words.map(function(word) { return `${word} `}); + quoteElement.innerHTML = spanWords.join(''); + quoteElement.childNodes[0].className = 'highlight'; + messageElement.innerText = ''; + typedValueElement.value = ''; + typedValueElement.disabled = false; //reverting if user is trying to click start for 2nd time since it is already disabled + typedValueElement.focus(); + startTime = new Date().getTime(); + + + +typedValueElement.addEventListener('input', () => { + const currentword = words[wordIndex]; + const typedValue = typedValueElement.value; //and typedValueElement.innerHTML.innertext is wrong + if(typedValue === currentword && wordIndex === words.length -1 ){ + const elapsedTime = new Date().getTime() - startTime; + const message = `CONGRATULATIONS! You finished in ${elapsedTime/1000} seconds.`; + messageElement.innerText = message; + typedValueElement.value = ''; //clear the input box + typedValueElement.disabled = true; //disable the input box + quoteElement.innerText="";//here, .value is not added + //typedValueElement.removeEventListener(); //remove the event listener + if (!localStorage.getItem("highest score") || elapsedTime/1000 < (localStorage.getItem("highest score"))) { + localStorage.setItem("highest score", elapsedTime/1000); + console.log(elapsedTime/1000) + } + + + + }else if(typedValue.endsWith(' ') && typedValue.trim() === currentword){ + typedValueElement.value = ''; + wordIndex++; + for(const wordElement of quoteElement.childNodes){ + wordElement.className = ''; + } + quoteElement.childNodes[wordIndex].className = 'highlight'; + + + }else if(currentword.startsWith(typedValue)){ + typedValueElement.className = ''; + } + else{ + typedValueElement.className = 'error'; + } + + + +})}); + + +leaderboard.addEventListener('click', () => { + highscore.innerHTML = localStorage.getItem("highest score"); +}); \ No newline at end of file diff --git a/3-typing-game/typing-game/game/style.css b/3-typing-game/typing-game/game/style.css new file mode 100644 index 0000000..4b94923 --- /dev/null +++ b/3-typing-game/typing-game/game/style.css @@ -0,0 +1,12 @@ +.highlight { + background-color: yellow; + } + + .error { + background-color: lightcoral; + border: red; + } + + #leaderboard{ + margin-top: 20px; + } \ No newline at end of file