Skip to content

Pallavi exercise mouse coordinates #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion 5-testing-components/examples/3-list-loop/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ export const list = (arr, startNum = 1) => {
liEl.innerText = string;
olEl.appendChild(liEl);
}

return olEl;
};
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,20 @@
* @param {Array[]} arrayOfArrays - a 2D array representing the game board
* @returns {HTMLTableElement} the rendered game board
*/
export const gameBoard = (arrayOfArrays) => {};
export const gameBoard = (arrayOfArrays) => {
console.log(arrayOfArrays);
const table = document.createElement('table');

for (const array of arrayOfArrays) {
console.log(array);
const tr = document.createElement('tr');
for (const element of array) {
console.log(element);
const td = document.createElement('td');
td.innerText = element;
tr.appendChild(td);
}
table.appendChild(tr);
}
return table;
};
29 changes: 20 additions & 9 deletions 5-testing-components/exercises-write-components/info/info.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,30 @@
* @param {string} caption - the title of this info drop-down
* @param {string} mainText - the important information
* @param {string} [id=''] - the element's id
* @param {string} [captionColor ='black'] - the color of the caption
* @param {string} [mainTextColor='black'] - the color of the main text
* @returns {HTMLDetailsElement}
*/
export const info = (caption, mainText, id = '') => {
const detailsEl = document.createElement('_');
_;
export const info = (
caption,
mainText,
id = 'details',
captionColor = 'black',
mainTextColor = 'black',
) => {
const detailsEl = document.createElement('details');
detailsEl.id = id;

const summaryEl = document.createElement('_');
_;
_;
const summaryEl = document.createElement('summary');
summaryEl.textContent = summary;
summaryEl.style.color = captionColor;

const pEl = document.createElement('_');
_;
_;
const pEl = document.createElement('p');
pEl.textContent = mainText;
pEl.style.color = mainTextColor;

detailsEl.appendChild(summaryEl);
detailsEl.appendChild(pEl);

return detailsEl;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const REVERSE_INPUT = 'input';
export const REVERSED_OUTPUT = 'output';
export const KEY_UP = 'key-up';
23 changes: 21 additions & 2 deletions 6-refactoring/exercises/dom-and-events/flip-book/src/handler.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
// import { reverseAndUpper } from './utils.js';
import { reverseAndUpper } from './util.js';

export const reverseAndUpperHandler = _;
export const reverseAndUpperHandler = (event) => {
debugger;
// read and process user input
const input = event.target.value;
console.log(event);

// execute core logic- utils
/*const upperCased = input.toUpperCase();
const splitted = upperCased.split('');
const reversed = splitted.reverse();*/
const reversedUppercase = reverseAndUpper(input);

// render result for user
document.getElementById(REVERSED_OUTPUT).innerHTML = reversedUppercase;

// log result for developers
console.log('\n --- user action ---');
console.log('input:', input);
console.log('reversedUppercase:', reversedUppercase);
};
15 changes: 11 additions & 4 deletions 6-refactoring/exercises/dom-and-events/flip-book/src/init.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
document.getElementById('input').addEventListener('keyup', (event) => {
import { REVERSE_INPUT, REVERSED_OUTPUT, KEY_UP } from '../data/constants';
import './listener.js';
// listener//

// document.get... addEventListener('typeEvent', handler)
// ----------------------listener-----------------------------|--handler-- till line 25--|
/*document.getElementById(REVERSE_INPUT).addEventListener(KEY_UP,(event) => {
debugger;
// read and process user input
const input = event.target.value;
console.log(event)

// execute core logic
// execute core logic- utils
const upperCased = input.toUpperCase();
const splitted = upperCased.split('');
const reversed = splitted.reverse();
const reversedUppercase = reversed.join('');

// render result for user
document.getElementById('output').innerHTML = reversedUppercase;
document.getElementById(REVERSED_OUTPUT).innerHTML = reversedUppercase;

// log result for developers
console.log('\n --- user action ---');
console.log('input:', input);
console.log('reversedUppercase:', reversedUppercase);
});
});*/
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
// import { reverseAndUpperHandler } from './handler.js';
import { reverseAndUpperHandler } from './handler.js';

document
.getElementById(REVERSE_INPUT)
.addEventListener(KEY_UP, reverseAndUpperHandler);
8 changes: 7 additions & 1 deletion 6-refactoring/exercises/dom-and-events/flip-book/src/util.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
/**
*
*/
export const reverseAndUpper = () => {};
export const reverseAndUpper = (input) => {
const upperCased = input.toUpperCase();
const splitted = upperCased.split('');
const reversed = splitted.reverse();
const reversedUppercase = reversed.join('');
return reversedUppercase;
};
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { reverseAndUpper } from './utils.js';
import { reverseAndUpper } from './util.js';

describe('reverseAndUpper: reverses a string and upper-cases all the letters', () => {
it('"lower-case letters"', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const MOUSE_USER_INTERFACE = 'user-interface';
export const MOUSE_MOVE = 'mousemove';
export const MOUSE_POSITION = 'mouse-position';
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
import { formatCoordinates } from './utils.js';
import { formatCoordinates } from './util.js';

export const showMouseCoordinates = () => {};
export const showMouseCoordinates = (event) => {
debugger;
// read & process user input
const xValue = event.pageX;
const yValue = event.pageY;

const formattedCoordinates = formatCoordinates(xValue,yValue);


// render result for user
document.getElementById(MOUSE_POSITION).innerHTML = formattedCoordinates;

// log action for developers
console.log('\n--- new coordinates ---');
console.log('x:', xValue);
console.log('y:', yValue);
}
;
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
document
.getElementById('user-interface')
.addEventListener('mousemove', (event) => {

import './listener.js'
/*document
.getElementById(MOUSE_USER_INTERFACE)
.addEventListener(MOUSE_MOVE, (event) => {
debugger;
// read & process user input
const xValue = event.pageX;
Expand All @@ -10,10 +12,10 @@ document
const formattedCoordinates = 'X: ' + xValue + '\nY: ' + yValue;

// render result for user
document.getElementById('mouse-position').innerHTML = formattedCoordinates;
document.getElementById(MOUSE_POSITION).innerHTML = formattedCoordinates;

// log action for developers
console.log('\n--- new coordinates ---');
console.log('x:', xValue);
console.log('y:', yValue);
});
});*/
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
import { showMouseCoordinates } from './handler.js';

document
.getElementById(MOUSE_USER_INTERFACE)
.addEventListener(MOUSE_MOVE, showMouseCoordinates);
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
/**
*
*/
export const formatCoordinates = () => {};
export const formatCoordinates = (xValue, yValue) => {

// execute core logic
const formattedCoordinates = 'X: ' + xValue + '\nY: ' + yValue;
return formattedCoordinates;
};
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { formatCoordinates } from './utils.js';
import { formatCoordinates } from './util.js';

describe('formatCoordinates: formats two numbers into a coordinates string', () => {
it('positive numbers', () => {
Expand Down
20 changes: 19 additions & 1 deletion 6-refactoring/exercises/state/no-copies/src/handler.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,22 @@
import { saveNoCopies } from './utils.js';
import { state } from '../data/state.js';

export const saveNoCopiesHandler = () => {};
export const saveNoCopiesHandler = () => {
let userInput = null;
while (userInput === null) {
userInput = prompt('enter a string to save');
}

// execute core logic
const alreadySaved = data.noCopies.includes(userInput);
if (!alreadySaved) {
data.noCopies.push(userInput);
}

// communicate result to user
const message = data.noCopies.join(', ');
alert(message);

// log interaction
console.log(data);
};
11 changes: 10 additions & 1 deletion 6-refactoring/exercises/state/no-copies/src/util.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
/**
*
*/
export const saveNoCopies = () => {};
export const saveNoCopies = () => {
const alreadySaved = data.noCopies.includes(userInput);
if (!alreadySaved) {
data.noCopies.push(userInput);
}

// communicate result to user
const message = data.noCopies.join(', ');
alert(message);
};
21 changes: 21 additions & 0 deletions exercises/convertTemperature/src/utils/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import {
SPACE,
TEMPERATURE_INPUT,
CONVERT_TEMPERATURE_CONTAINER,
MESSAGE_ERROR_NOT_INTEGER,
} from '../constants.js';

export const convertedTemperature = (fahrenheitTextList) => {
if (!/^[0-9\s]*$/.test(fahrenheitTextList)) {
window.alert(MESSAGE_ERROR_NOT_INTEGER).replace('%s', fahrenheitTextList);
}

// Sanitize it
const fahrenheitList = fahrenheitTextList.trim().split(SPACE);
const convertedTemperatures = fahrenheitList.map((fahrenheit) => {
const celsius = ((fahrenheit - 32) * 5) / 9;
return celsius.toFixed(2);
}).join(' ');
return convertedTemperatures;
};
export default convertedTemperature;