Skip to content

exercise-mouse-coordinate-done #5

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 2 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
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,16 @@
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;
// execute core logic
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,4 +1,7 @@
document

import './listener.js'

/*document
.getElementById('user-interface')
.addEventListener('mousemove', (event) => {
debugger;
Comment on lines +4 to 7
Copy link
Owner

@dannyelcf dannyelcf May 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can remove all these lines once you already import './listener.js'

Expand All @@ -16,4 +19,4 @@ document
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,13 @@
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,5 @@
/**
*
*/
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