fpythons 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (170) hide show
  1. fpythons/__init__.py +12 -0
  2. fpythons/__main__.py +4 -0
  3. fpythons/data/00_START_HERE.md +144 -0
  4. fpythons/data/ALL_SLIPS_CODE.txt +1854 -0
  5. fpythons/data/README.md +35 -0
  6. fpythons/data/Slip_01.md +160 -0
  7. fpythons/data/Slip_02.md +104 -0
  8. fpythons/data/Slip_03.md +95 -0
  9. fpythons/data/Slip_04.md +131 -0
  10. fpythons/data/Slip_05.md +120 -0
  11. fpythons/data/Slip_06.md +161 -0
  12. fpythons/data/Slip_07.md +121 -0
  13. fpythons/data/Slip_08.md +95 -0
  14. fpythons/data/Slip_09.md +92 -0
  15. fpythons/data/Slip_10.md +113 -0
  16. fpythons/data/Slip_11.md +109 -0
  17. fpythons/data/Slip_12.md +181 -0
  18. fpythons/data/Slip_13.md +163 -0
  19. fpythons/data/Slip_14.md +141 -0
  20. fpythons/data/Slip_15.md +100 -0
  21. fpythons/data/Slip_16.md +127 -0
  22. fpythons/data/Slip_17.md +93 -0
  23. fpythons/data/Slip_18.md +96 -0
  24. fpythons/data/Slip_19.md +94 -0
  25. fpythons/data/Slip_20.md +165 -0
  26. fpythons/data/Slip_21.md +122 -0
  27. fpythons/data/VIVA.md +195 -0
  28. fpythons/data/code/slip1/.gitignore +2 -0
  29. fpythons/data/code/slip1/package.json +31 -0
  30. fpythons/data/code/slip1/public/index.html +12 -0
  31. fpythons/data/code/slip1/src/App.js +7 -0
  32. fpythons/data/code/slip1/src/index.js +10 -0
  33. fpythons/data/code/slip1/src/slip1/loginForm.js +26 -0
  34. fpythons/data/code/slip1/src/slip1/style.css +46 -0
  35. fpythons/data/code/slip10/.gitignore +2 -0
  36. fpythons/data/code/slip10/package.json +31 -0
  37. fpythons/data/code/slip10/public/index.html +12 -0
  38. fpythons/data/code/slip10/src/App.js +7 -0
  39. fpythons/data/code/slip10/src/index.js +10 -0
  40. fpythons/data/code/slip10/src/slip10/SumOfDigits.js +37 -0
  41. fpythons/data/code/slip11/.gitignore +2 -0
  42. fpythons/data/code/slip11/package.json +31 -0
  43. fpythons/data/code/slip11/public/index.html +12 -0
  44. fpythons/data/code/slip11/src/App.js +7 -0
  45. fpythons/data/code/slip11/src/index.js +10 -0
  46. fpythons/data/code/slip11/src/slip11/StringOperation.js +33 -0
  47. fpythons/data/code/slip12/.gitignore +2 -0
  48. fpythons/data/code/slip12/package.json +33 -0
  49. fpythons/data/code/slip12/public/index.html +12 -0
  50. fpythons/data/code/slip12/src/App.js +7 -0
  51. fpythons/data/code/slip12/src/index.js +14 -0
  52. fpythons/data/code/slip12/src/slip12/NotesManagementApp.js +35 -0
  53. fpythons/data/code/slip12/src/slip12/redux/notesSlice.js +20 -0
  54. fpythons/data/code/slip12/src/slip12/redux/store.js +10 -0
  55. fpythons/data/code/slip13/.gitignore +2 -0
  56. fpythons/data/code/slip13/package.json +33 -0
  57. fpythons/data/code/slip13/public/index.html +12 -0
  58. fpythons/data/code/slip13/src/App.js +7 -0
  59. fpythons/data/code/slip13/src/index.js +14 -0
  60. fpythons/data/code/slip13/src/slip13/Counter.js +20 -0
  61. fpythons/data/code/slip13/src/slip13/redux/counterSlice.js +19 -0
  62. fpythons/data/code/slip13/src/slip13/redux/store.js +10 -0
  63. fpythons/data/code/slip14/.gitignore +2 -0
  64. fpythons/data/code/slip14/package.json +31 -0
  65. fpythons/data/code/slip14/public/index.html +12 -0
  66. fpythons/data/code/slip14/src/App.js +7 -0
  67. fpythons/data/code/slip14/src/index.js +10 -0
  68. fpythons/data/code/slip14/src/slip14/Calculator.js +64 -0
  69. fpythons/data/code/slip15/.gitignore +2 -0
  70. fpythons/data/code/slip15/package.json +31 -0
  71. fpythons/data/code/slip15/public/index.html +12 -0
  72. fpythons/data/code/slip15/src/App.js +7 -0
  73. fpythons/data/code/slip15/src/index.js +10 -0
  74. fpythons/data/code/slip15/src/slip15/Counter.js +24 -0
  75. fpythons/data/code/slip16/.gitignore +2 -0
  76. fpythons/data/code/slip16/package.json +31 -0
  77. fpythons/data/code/slip16/public/index.html +12 -0
  78. fpythons/data/code/slip16/src/App.js +7 -0
  79. fpythons/data/code/slip16/src/index.js +10 -0
  80. fpythons/data/code/slip16/src/slip16/TraditionalDOM.html +24 -0
  81. fpythons/data/code/slip16/src/slip16/VirtualDOM.js +16 -0
  82. fpythons/data/code/slip17/.gitignore +2 -0
  83. fpythons/data/code/slip17/package.json +31 -0
  84. fpythons/data/code/slip17/public/index.html +12 -0
  85. fpythons/data/code/slip17/src/App.js +7 -0
  86. fpythons/data/code/slip17/src/index.js +10 -0
  87. fpythons/data/code/slip17/src/slip17/Sign-in.js +17 -0
  88. fpythons/data/code/slip18/.gitignore +2 -0
  89. fpythons/data/code/slip18/package.json +31 -0
  90. fpythons/data/code/slip18/public/index.html +12 -0
  91. fpythons/data/code/slip18/public/logo192.png +0 -0
  92. fpythons/data/code/slip18/src/App.js +7 -0
  93. fpythons/data/code/slip18/src/index.js +10 -0
  94. fpythons/data/code/slip18/src/slip18/Profile.js +20 -0
  95. fpythons/data/code/slip19/.gitignore +2 -0
  96. fpythons/data/code/slip19/package.json +31 -0
  97. fpythons/data/code/slip19/public/index.html +12 -0
  98. fpythons/data/code/slip19/src/App.js +7 -0
  99. fpythons/data/code/slip19/src/index.js +10 -0
  100. fpythons/data/code/slip19/src/slip19/Movies.js +19 -0
  101. fpythons/data/code/slip2/.gitignore +2 -0
  102. fpythons/data/code/slip2/package.json +31 -0
  103. fpythons/data/code/slip2/public/index.html +12 -0
  104. fpythons/data/code/slip2/src/App.js +7 -0
  105. fpythons/data/code/slip2/src/index.js +10 -0
  106. fpythons/data/code/slip2/src/slip2/useEffect.js +23 -0
  107. fpythons/data/code/slip20/.gitignore +2 -0
  108. fpythons/data/code/slip20/package.json +32 -0
  109. fpythons/data/code/slip20/public/index.html +12 -0
  110. fpythons/data/code/slip20/src/App.js +16 -0
  111. fpythons/data/code/slip20/src/index.js +10 -0
  112. fpythons/data/code/slip20/src/slip20/Login.js +45 -0
  113. fpythons/data/code/slip20/src/slip20/Students.js +27 -0
  114. fpythons/data/code/slip21/.gitignore +2 -0
  115. fpythons/data/code/slip21/package.json +31 -0
  116. fpythons/data/code/slip21/public/index.html +12 -0
  117. fpythons/data/code/slip21/src/App.js +7 -0
  118. fpythons/data/code/slip21/src/index.js +10 -0
  119. fpythons/data/code/slip21/src/slip21/NumberString.js +46 -0
  120. fpythons/data/code/slip3/.gitignore +2 -0
  121. fpythons/data/code/slip3/package.json +31 -0
  122. fpythons/data/code/slip3/public/index.html +12 -0
  123. fpythons/data/code/slip3/src/App.js +7 -0
  124. fpythons/data/code/slip3/src/index.js +10 -0
  125. fpythons/data/code/slip3/src/slip3/toggleBtn.js +16 -0
  126. fpythons/data/code/slip4/.gitignore +2 -0
  127. fpythons/data/code/slip4/package.json +32 -0
  128. fpythons/data/code/slip4/public/index.html +12 -0
  129. fpythons/data/code/slip4/src/App.js +23 -0
  130. fpythons/data/code/slip4/src/index.js +10 -0
  131. fpythons/data/code/slip4/src/slip4/About.js +7 -0
  132. fpythons/data/code/slip4/src/slip4/Contact.js +7 -0
  133. fpythons/data/code/slip4/src/slip4/home.js +7 -0
  134. fpythons/data/code/slip5/.gitignore +2 -0
  135. fpythons/data/code/slip5/package.json +32 -0
  136. fpythons/data/code/slip5/public/index.html +12 -0
  137. fpythons/data/code/slip5/src/App.js +18 -0
  138. fpythons/data/code/slip5/src/index.js +10 -0
  139. fpythons/data/code/slip5/src/slip5/loginValidation.js +30 -0
  140. fpythons/data/code/slip6/.gitignore +2 -0
  141. fpythons/data/code/slip6/package.json +32 -0
  142. fpythons/data/code/slip6/public/index.html +12 -0
  143. fpythons/data/code/slip6/src/App.js +31 -0
  144. fpythons/data/code/slip6/src/index.js +10 -0
  145. fpythons/data/code/slip6/src/slip6/Dashboard.js +12 -0
  146. fpythons/data/code/slip6/src/slip6/Login.js +23 -0
  147. fpythons/data/code/slip6/src/slip6/ProtectedRoute.js +10 -0
  148. fpythons/data/code/slip7/.gitignore +2 -0
  149. fpythons/data/code/slip7/package.json +31 -0
  150. fpythons/data/code/slip7/public/index.html +12 -0
  151. fpythons/data/code/slip7/src/App.js +7 -0
  152. fpythons/data/code/slip7/src/index.js +10 -0
  153. fpythons/data/code/slip7/src/slip7/TodoList.js +42 -0
  154. fpythons/data/code/slip8/.gitignore +2 -0
  155. fpythons/data/code/slip8/package.json +31 -0
  156. fpythons/data/code/slip8/public/index.html +12 -0
  157. fpythons/data/code/slip8/src/App.js +7 -0
  158. fpythons/data/code/slip8/src/index.js +10 -0
  159. fpythons/data/code/slip8/src/slip8/ToggleButton.js +19 -0
  160. fpythons/data/code/slip9/.gitignore +2 -0
  161. fpythons/data/code/slip9/package.json +31 -0
  162. fpythons/data/code/slip9/public/index.html +12 -0
  163. fpythons/data/code/slip9/src/App.js +7 -0
  164. fpythons/data/code/slip9/src/index.js +10 -0
  165. fpythons/data/code/slip9/src/slip9/Counter.js +16 -0
  166. fpythons/main.py +226 -0
  167. fpythons-0.1.0.dist-info/METADATA +64 -0
  168. fpythons-0.1.0.dist-info/RECORD +170 -0
  169. fpythons-0.1.0.dist-info/WHEEL +4 -0
  170. fpythons-0.1.0.dist-info/entry_points.txt +2 -0
@@ -0,0 +1,93 @@
1
+ # Slip 17: Sign in and sign out
2
+
3
+ [All slips](README.md) | [Basics: read first](00_START_HERE.md) | [Viva](VIVA.md)
4
+
5
+ ## 1. Question
6
+
7
+ Create Sign-In and Sign-Out functionality using the `useState()` hook. On Sign in show "Hello, Welcome in Home Page"; on Sign out show "Please sign in first".
8
+
9
+ ## 2. Files you will touch
10
+
11
+ ```text
12
+ slip17/
13
+ src/slip17/Sign-in.js
14
+ src/App.js
15
+ ```
16
+
17
+ ## 3. Commands (PowerShell, in this order)
18
+
19
+ ```powershell
20
+ npx create-react-app slip17
21
+ cd slip17
22
+ mkdir src\slip17
23
+ code .
24
+ ```
25
+
26
+ ## 4. Write the code
27
+
28
+ ### Step 1: `src/slip17/Sign-in.js`
29
+
30
+ ```jsx
31
+ import React, {useState} from 'react'
32
+
33
+ const SignIn = () => {
34
+
35
+ const [isLoggedIn, setIsLoggedIn] = useState(false);
36
+
37
+ return (
38
+ <div>
39
+ <h2>SignIn SignOut</h2>
40
+ {isLoggedIn ? <h3>Hello! Welcome in Home page.</h3> : <h3>Please login first.</h3>}
41
+ {!isLoggedIn && (<button onClick={() => setIsLoggedIn(true)}>Sign in</button>)}
42
+ {isLoggedIn && (<button onClick={() => setIsLoggedIn(false)}>Sign out</button>)}
43
+ </div>
44
+ )
45
+ }
46
+
47
+ export default SignIn
48
+ ```
49
+
50
+ ### Step 2: `src/App.js`
51
+
52
+ ```jsx
53
+ import SignIn from './slip17/Sign-in';
54
+
55
+ function App() {
56
+ return <SignIn />;
57
+ }
58
+
59
+ export default App;
60
+ ```
61
+
62
+ ## 5. How it works
63
+
64
+ - `isLoggedIn` is a boolean, `false` at the start.
65
+ - A ternary picks the message.
66
+ - `&&` shows only the button that applies.
67
+
68
+ ## 6. Run it
69
+
70
+ ```powershell
71
+ npm start
72
+ ```
73
+
74
+ Click **Sign in**, then **Sign out**.
75
+
76
+ ## 7. Errors and fixes
77
+
78
+ | Problem | Fix |
79
+ |---|---|
80
+ | Both buttons show | check the conditions before `&&` |
81
+ | `Too many re-renders` | write `onClick={() => setIsLoggedIn(true)}` |
82
+
83
+ ## 8. Viva questions
84
+
85
+ **Q. How does `&&` rendering work?**
86
+ The right side is shown only when the left side is true.
87
+
88
+ **Q. What does `useState` return?**
89
+ The current value and a function to change it.
90
+
91
+ ---
92
+
93
+ Solved project: [code/slip17](code/slip17/)
@@ -0,0 +1,96 @@
1
+ # Slip 18: Profile page
2
+
3
+ [All slips](README.md) | [Basics: read first](00_START_HERE.md) | [Viva](VIVA.md)
4
+
5
+ ## 1. Question
6
+
7
+ Create a React application that displays your name, a short bio, an image and a description of your profile.
8
+
9
+ ## 2. Files you will touch
10
+
11
+ ```text
12
+ slip18/
13
+ src/slip18/Profile.js
14
+ src/App.js
15
+ ```
16
+
17
+ ## 3. Commands (PowerShell, in this order)
18
+
19
+ ```powershell
20
+ npx create-react-app slip18
21
+ cd slip18
22
+ mkdir src\slip18
23
+ code .
24
+ ```
25
+
26
+ ## 4. Write the code
27
+
28
+ ### Step 1: `src/slip18/Profile.js`
29
+
30
+ ```jsx
31
+ import React from 'react';
32
+
33
+ const Profile = () => {
34
+
35
+ const name = "Your Name";
36
+ const bio = "I'm a Second year M.Sc.CA student.";
37
+ const desc = "Learning React";
38
+
39
+ return (
40
+ <div>
41
+ <h2>My Profile</h2>
42
+ <h3>{name}</h3>
43
+ <p>{bio}</p>
44
+ <img src='/logo192.png' alt='logo'></img>
45
+ <p>{desc}</p>
46
+ </div>
47
+ )
48
+ }
49
+
50
+ export default Profile
51
+ ```
52
+
53
+ ### Step 2: `src/App.js`
54
+
55
+ ```jsx
56
+ import Profile from './slip18/Profile';
57
+
58
+ function App() {
59
+ return <Profile />;
60
+ }
61
+
62
+ export default App;
63
+ ```
64
+
65
+ ## 5. How it works
66
+
67
+ - The details are constants shown with `{ }` in JSX.
68
+ - `/logo192.png` is read from the `public` folder. To use your photo, copy it into `public` and change `src`.
69
+ - Replace the name, bio and description with your own.
70
+
71
+ ## 6. Run it
72
+
73
+ ```powershell
74
+ npm start
75
+ ```
76
+
77
+ The name, bio, image and description appear.
78
+
79
+ ## 7. Errors and fixes
80
+
81
+ | Problem | Fix |
82
+ |---|---|
83
+ | Broken image | the file must be in `public` and the name must match |
84
+ | JSX error on `img` | close the tag: `<img />` |
85
+
86
+ ## 8. Viva questions
87
+
88
+ **Q. What is the `public` folder?**
89
+ Files in it are served as they are, from the site root.
90
+
91
+ **Q. What is `alt` for?**
92
+ Text shown or read aloud when the image cannot be seen.
93
+
94
+ ---
95
+
96
+ Solved project: [code/slip18](code/slip18/)
@@ -0,0 +1,94 @@
1
+ # Slip 19: List of 10 favourite movies
2
+
3
+ [All slips](README.md) | [Basics: read first](00_START_HERE.md) | [Viva](VIVA.md)
4
+
5
+ ## 1. Question
6
+
7
+ Design a functional component which displays a list of 10 favourite movies using JSX.
8
+
9
+ ## 2. Files you will touch
10
+
11
+ ```text
12
+ slip19/
13
+ src/slip19/Movies.js
14
+ src/App.js
15
+ ```
16
+
17
+ ## 3. Commands (PowerShell, in this order)
18
+
19
+ ```powershell
20
+ npx create-react-app slip19
21
+ cd slip19
22
+ mkdir src\slip19
23
+ code .
24
+ ```
25
+
26
+ ## 4. Write the code
27
+
28
+ ### Step 1: `src/slip19/Movies.js`
29
+
30
+ ```jsx
31
+ import React from 'react'
32
+
33
+ const Movies = () => {
34
+
35
+ const movies = ['3 idiots', 'Bhag milkha bhag', 'Shershah', 'Amaran', 'Avengers', 'Drishyam', 'Golmaal', 'Singham', 'Mitwa', 'Timepass'];
36
+
37
+ return (
38
+ <div>
39
+ <h2>Favorite Movies List</h2>
40
+ <ul>
41
+ {movies.map((item, index) =>(
42
+ <li key={index}>{item}</li>
43
+ ))}
44
+ </ul>
45
+ </div>
46
+ )
47
+ }
48
+
49
+ export default Movies
50
+ ```
51
+
52
+ ### Step 2: `src/App.js`
53
+
54
+ ```jsx
55
+ import Movies from './slip19/Movies';
56
+
57
+ function App() {
58
+ return <Movies />;
59
+ }
60
+
61
+ export default App;
62
+ ```
63
+
64
+ ## 5. How it works
65
+
66
+ - The movies are kept in an array.
67
+ - `map` returns one `<li>` for each movie, with a `key`.
68
+
69
+ ## 6. Run it
70
+
71
+ ```powershell
72
+ npm start
73
+ ```
74
+
75
+ Ten movie names appear as a list.
76
+
77
+ ## 7. Errors and fixes
78
+
79
+ | Problem | Fix |
80
+ |---|---|
81
+ | Nothing shows | with `{ }` after the arrow you need `return` |
82
+ | `key` warning | add `key` to the `<li>` |
83
+
84
+ ## 8. Viva questions
85
+
86
+ **Q. What is a functional component?**
87
+ A JavaScript function that returns JSX.
88
+
89
+ **Q. Why use `map` instead of `forEach`?**
90
+ `map` returns a new array that JSX can show.
91
+
92
+ ---
93
+
94
+ Solved project: [code/slip19](code/slip19/)
@@ -0,0 +1,165 @@
1
+ # Slip 20: Login with route parameters
2
+
3
+ [All slips](README.md) | [Basics: read first](00_START_HERE.md) | [Viva](VIVA.md)
4
+
5
+ ## 1. Question
6
+
7
+ Create a login system to pass parameters through routes and display dynamic data (for example `/user/:id` should show user details).
8
+
9
+ ## 2. Files you will touch
10
+
11
+ ```text
12
+ slip20/
13
+ src/slip20/Login.js
14
+ src/slip20/Students.js
15
+ src/App.js
16
+ ```
17
+
18
+ ## 3. Commands (PowerShell, in this order)
19
+
20
+ ```powershell
21
+ npx create-react-app slip20
22
+ cd slip20
23
+ npm install react-router-dom
24
+ mkdir src\slip20
25
+ code .
26
+ ```
27
+
28
+ ## 4. Write the code
29
+
30
+ ### Step 1: `src/slip20/Login.js`
31
+
32
+ ```jsx
33
+ import React, { useState } from 'react';
34
+ import { useNavigate } from 'react-router-dom';
35
+
36
+ const Login = () => {
37
+
38
+ const [id, setId] = useState('');
39
+ const [username, setUsername] = useState('');
40
+ const [password, setPassword] = useState('');
41
+ const navigate = useNavigate();
42
+
43
+ const users = [
44
+ {id: 101, name: 'Asha'},
45
+ {id: 102, name: 'Rahul'},
46
+ {id: 103, name: 'Urmila'},
47
+ {id: 104, name: 'Satish'}
48
+ ];
49
+
50
+ const handleSubmit = (e) =>{
51
+ e.preventDefault();
52
+ const user = users.find((item) => item.id === Number(id));
53
+ if(user !== undefined && username === 'Admin' && password === '1234'){
54
+ navigate(`/user/${id}`);
55
+ }
56
+ else{
57
+ alert("Invalid credentials");
58
+ }
59
+ console.log("Id: ", id);
60
+ console.log("Username: ", username);
61
+ console.log("Password: ", password);
62
+ }
63
+
64
+ return (
65
+ <div>
66
+ <h2>Login Form</h2>
67
+ <form onSubmit={handleSubmit}>
68
+ <label>UserId<input type='text' value={id} onChange={(e) => setId(e.target.value)}></input></label><br></br>
69
+ <label>Username<input type='text' value={username} onChange={(e) => setUsername(e.target.value)}></input></label><br></br>
70
+ <label>Password<input type='password' value={password} onChange={(e) => setPassword(e.target.value)}></input></label><br></br>
71
+ <button type='submit'>Login</button>
72
+ </form>
73
+ </div>
74
+ )
75
+ }
76
+
77
+ export default Login
78
+ ```
79
+
80
+ ### Step 2: `src/slip20/Students.js`
81
+
82
+ ```jsx
83
+ import React from 'react';
84
+ import {useParams} from 'react-router-dom';
85
+
86
+ const Students = () => {
87
+
88
+ const {id} = useParams();
89
+ const users = [
90
+ {id: 101, name: 'Asha'},
91
+ {id: 102, name: 'Rahul'},
92
+ {id: 103, name: 'Urmila'},
93
+ {id: 104, name: 'Satish'}
94
+ ];
95
+
96
+ const user = users.find((item) => item.id === Number(id));
97
+
98
+ return (
99
+ <div>
100
+ {user ? (<div>
101
+ <h2>Student Id: {user.id}</h2>
102
+ <p>Student Name: {user.name}</p>
103
+ </div>
104
+ ) : (<h2>User not found</h2>)}
105
+ </div>
106
+ )
107
+ }
108
+
109
+ export default Students
110
+ ```
111
+
112
+ ### Step 3: `src/App.js`
113
+
114
+ ```jsx
115
+ import { BrowserRouter, Routes, Route } from 'react-router-dom';
116
+ import Login from './slip20/Login';
117
+ import Students from './slip20/Students';
118
+
119
+ function App() {
120
+ return (
121
+ <BrowserRouter>
122
+ <Routes>
123
+ <Route path="/" element={<Login />} />
124
+ <Route path="/user/:id" element={<Students />} />
125
+ </Routes>
126
+ </BrowserRouter>
127
+ );
128
+ }
129
+
130
+ export default App;
131
+ ```
132
+
133
+ ## 5. How it works
134
+
135
+ - `Login` checks that the id exists and the credentials are `Admin` / `1234`.
136
+ - `navigate(`/user/${id}`)` puts the id in the address.
137
+ - `Students` reads it with `useParams` and finds the matching user.
138
+ - `useParams` gives a string, so it is converted with `Number()`.
139
+
140
+ ## 6. Run it
141
+
142
+ ```powershell
143
+ npm start
144
+ ```
145
+
146
+ Login with id `101`, username `Admin`, password `1234`. Then open `/user/999` to see "User not found".
147
+
148
+ ## 7. Errors and fixes
149
+
150
+ | Problem | Fix |
151
+ |---|---|
152
+ | Always "User not found" | compare numbers: `item.id === Number(id)` |
153
+ | `id` is undefined | the route must be `/user/:id` |
154
+
155
+ ## 8. Viva questions
156
+
157
+ **Q. What is a route parameter?**
158
+ A changing part of the address, written as `:name` in the route.
159
+
160
+ **Q. What does `useParams` return?**
161
+ An object with the parameters of the current route.
162
+
163
+ ---
164
+
165
+ Solved project: [code/slip20](code/slip20/)
@@ -0,0 +1,122 @@
1
+ # Slip 21: Even/odd and palindrome
2
+
3
+ [All slips](README.md) | [Basics: read first](00_START_HERE.md) | [Viva](VIVA.md)
4
+
5
+ ## 1. Question
6
+
7
+ Take a number and a string from the user. Check whether the number is even or odd and whether the string is a palindrome. Display appropriate messages.
8
+
9
+ ## 2. Files you will touch
10
+
11
+ ```text
12
+ slip21/
13
+ src/slip21/NumberString.js
14
+ src/App.js
15
+ ```
16
+
17
+ ## 3. Commands (PowerShell, in this order)
18
+
19
+ ```powershell
20
+ npx create-react-app slip21
21
+ cd slip21
22
+ mkdir src\slip21
23
+ code .
24
+ ```
25
+
26
+ ## 4. Write the code
27
+
28
+ ### Step 1: `src/slip21/NumberString.js`
29
+
30
+ ```jsx
31
+ import React, { useState } from 'react';
32
+
33
+ const NumberString = () => {
34
+
35
+ const [number, setNumber] = useState('');
36
+ const [string, setString] = useState('');
37
+ const [numberResult, setNumberResult] = useState(null);
38
+ const [stringResult, setStringResult] = useState(null);
39
+
40
+ const EvenOdd = () =>{
41
+ if(Number(number) % 2 === 0){
42
+ setNumberResult("Even");
43
+ }else{
44
+ setNumberResult("Odd");
45
+ }
46
+ }
47
+
48
+ const checkPalindrome = () =>{
49
+ let str = string.split('').reverse().join('');
50
+ if(str === string){
51
+ setStringResult("Palindrome");
52
+ }else{
53
+ setStringResult("Not palidrome");
54
+ }
55
+ }
56
+
57
+ const handleSubmit = (e) =>{
58
+ e.preventDefault();
59
+ EvenOdd();
60
+ checkPalindrome();
61
+ }
62
+
63
+ return (
64
+ <div>
65
+ <form onSubmit={handleSubmit}>
66
+ <label>Enter number:<input type='text' value={number} onChange={(e) => setNumber(e.target.value)}></input></label>
67
+ <label>Enter string:<input type='text' value={string} onChange={(e) => setString(e.target.value)}></input></label>
68
+ <button type='submit'>Check</button>
69
+ </form>
70
+ <p>Number is {numberResult}</p>
71
+ <p>String is {stringResult}</p>
72
+ </div>
73
+ )
74
+ }
75
+
76
+ export default NumberString
77
+ ```
78
+
79
+ ### Step 2: `src/App.js`
80
+
81
+ ```jsx
82
+ import NumberString from './slip21/NumberString';
83
+
84
+ function App() {
85
+ return <NumberString />;
86
+ }
87
+
88
+ export default App;
89
+ ```
90
+
91
+ ## 5. How it works
92
+
93
+ - `Number(number) % 2 === 0` means even.
94
+ - The string is reversed with `split('').reverse().join('')` and compared with the original.
95
+ - One submit runs both checks.
96
+
97
+ ## 6. Run it
98
+
99
+ ```powershell
100
+ npm start
101
+ ```
102
+
103
+ Enter `4` and `madam`, then `7` and `react`. The palindrome check is case sensitive.
104
+
105
+ ## 7. Errors and fixes
106
+
107
+ | Problem | Fix |
108
+ |---|---|
109
+ | `Madam` is not a palindrome | compare after `toLowerCase()` |
110
+ | Blank number shows "Even" | check for blank input before testing |
111
+
112
+ ## 8. Viva questions
113
+
114
+ **Q. What is a palindrome?**
115
+ Text that reads the same forwards and backwards.
116
+
117
+ **Q. What does the `%` operator give?**
118
+ The remainder of a division.
119
+
120
+ ---
121
+
122
+ Solved project: [code/slip21](code/slip21/)