<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Paullaster Okoth on Medium]]></title>
        <description><![CDATA[Stories by Paullaster Okoth on Medium]]></description>
        <link>https://medium.com/@paullasterokoth98?source=rss-3dacee07f8eb------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*xo_UNncfQXSEqsPVRaZb1A.jpeg</url>
            <title>Stories by Paullaster Okoth on Medium</title>
            <link>https://medium.com/@paullasterokoth98?source=rss-3dacee07f8eb------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 13:31:02 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@paullasterokoth98/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Nested Named Views in Vue.js?]]></title>
            <link>https://paullasterokoth98.medium.com/nested-named-views-in-vue-js-1244eedde756?source=rss-3dacee07f8eb------2</link>
            <guid isPermaLink="false">https://medium.com/p/1244eedde756</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[vuejs]]></category>
            <category><![CDATA[vue-router]]></category>
            <dc:creator><![CDATA[Paullaster Okoth]]></dc:creator>
            <pubDate>Mon, 03 Apr 2023 13:43:26 GMT</pubDate>
            <atom:updated>2023-04-03T13:43:26.969Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ue7bAbV-nigpltppsvqHLA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kHfqppfhdA7mFSL5ZcUn0Q.png" /><figcaption>images showing settings nested views: for email route and profile route</figcaption></figure><p>Vue-Router is the official Vue.js routing library.</p><p>According to the authors, Vue Router is,</p><blockquote>“Expressive, configurable and convenient routing for Vue.js”</blockquote><p>Today, in this well explained and easy to understand blog, I want to leverage your learning curve by introducing you to the need-to-know features of Vue Router, that is, Nested Named Views.</p><p>We’ll pick a common usecase for our illustration. To follow along, you need to setup a Vue.js v3 project.</p><p>I’m using vite to scafold my initial vue project</p><pre>#npm v7+<br>npm create vite@latest vuerouter -- - template vue</pre><p>After creating you initial project structure, run:</p><pre>npm install</pre><p>to install all the dependencies. Once done, open the project in your favorite code editor, I’m using visual studio code, then navigate to <em>src </em>folder inside the <em>root </em>folder of your project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/379/1*0h05_w9qwyCAUR1GLBm2pQ.png" /><figcaption>vue.js project folder structure</figcaption></figure><p>clear everything inside, <em>main.js</em> and <em>app.vue. A</em>lso feel free to delete the style.css file you’ll not need it for this illustration.</p><p>Now it’s time to get our hands dirty.</p><p>First we are going to create a new directory and call it<em> views</em>, you can call it anything that suites you. Inside views folder, for our example project, we’re going to create the following files:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/337/1*6Dy50Rm2KPaswhS6EjQeLw.png" /><figcaption>views folder structure</figcaption></figure><p>We’ll use the <em>index.js</em> file to export all the <em>.vue</em> files inside the views folder.</p><p>Let’s create our first screen. Go to<em> app.vue</em> file, and add this piece of code, feel free to copy and paste as this is a basic vue file.</p><pre>&lt;template&gt;<br>   &lt;h1&gt; <br>    Vue Router Nested Named Views <br>  &lt;/h1&gt;<br>&lt;/tempate&gt;<br>&lt;script&gt;<br>export default {<br>  name: &quot;App&quot;<br>}<br>&lt;/script&gt;</pre><p>In the <em>main.js </em>file, add the following code:</p><pre>import {createApp} from &#39;vue&#39;;<br>import App from &#39;./App.vue&#39;;<br><br>const app = createApp(App)<br>app.mount(&#39;#app&#39;)</pre><p>We’ll use vscode’s in-built terminal for this example project. On terminal run the following command to start your vue app.</p><pre>npm run dev</pre><p>Go to your browser and enter the url on your terminal in the browser url bar. Enjoy what you’re seeing.</p><p>Next, we need to install vue-router library using the following command:</p><pre>npm install vue-router</pre><p>Let’s setup our routes now. In the <em>src</em> folder, create a file, I’ll name it <em>router.js</em>, you can name it anything provided it is making sense for you.</p><p>We’ll add the following code to the <em>router.js</em> file:</p><pre>import { createRouter, createWebHashHistory } from &#39;vue-router&#39;;<br>import { Settings, Email, Subscription, Profile, ChangeProfile, ViewProfile } from &#39;./views&#39;<br><br>const routes = [<br>  {<br>        path: &#39;/settings&#39;,<br>        component: Settings,<br>        name: &#39;settings&#39;,<br>        children: [<br>            {<br>                path: &#39;email&#39;,<br>                components: {default: Email, subscriptions: Subscription},<br>                name: &#39;email&#39;,<br>            },<br>            {<br>                path: &#39;profile&#39;,<br>                components: {<br>                    default: Profile,<br>                    changeProfile: ChangeProfile,<br>                    viewProfile: ViewProfile<br>                },<br>                name: &#39;profile&#39;<br>            }<br>        ]<br>    }<br>];<br><br>const router = createRouter({<br>    history: createWebHashHistory(),<br>    routes,<br>});<br><br>export { router };</pre><p>Here, we are importing two methods from vue-router library, <em>createRouter</em> and <em>createWebHasHistory</em> methods</p><p><em>createRouter — </em>Creates a Router instance that can be used by a Vue app.</p><p><em>createWebHashHistory —</em> gives a url of `https://example.com/folder#<em>`</em></p><p>We’re also importing the files we created inside <em>views </em>folder from index.js file inside the <em>views </em>folder. We have also defined a routes array — routes is an array of objects that must include the following properties;</p><p><em>path </em>— a string specifing the segment of url.</p><p><em>component — </em>Vue component whose content should be displayed when we navigate to this url segment. The routes objects can have other more optional properties like <em>name</em>, <em>children </em>and more…</p><p>We’re creating a route with <em>path </em>, <em>/settings, and we are using Settings component. This route has children routes, i.e, email and profile that we’re going to use to display name routes — Subscription, ChangeProfile, ViewProfile.</em></p><p>Notice that we’re displaying multiple views and the unnamed route takes the default name — . In the components object, the keys become the names of the view and the components to display are the values.</p><p>We finish by creating <em>router </em>using <em>createRouter </em>method and exporting it.</p><p>Let’s go and modify our main.js file to look like this;</p><pre>import {createApp} from &#39;vue&#39;;<br>import App from &#39;./App.vue&#39;;<br>import {router} from &#39;./router&#39;;<br><br>const app = createApp(App).use(router);<br>app.mount(&#39;#app&#39;)</pre><p>We only imported router, and instructed our application to use the router we’ve just created.</p><p>Inside the <em>views </em>folder, have something like this for all the .<em>vue </em>files except for <em>Settings.vue</em></p><pre>&lt;template&gt;<br>    &lt;div&gt;<br>        view profile<br>    &lt;/div&gt;<br>&lt;/template&gt;<br>&lt;script&gt;<br>export default {<br>    name: &quot;ViewProfile&quot;,<br>}<br>&lt;/script&gt;</pre><p>modify the text between the<em> div</em> to suite each file you have.</p><p>Now we’re going to add the following code to <em>Settings.vue</em> file:</p><pre>&lt;template&gt;<br>    &lt;div class=&quot;grid&quot;&gt;<br>        &lt;sidebar class=&quot;sidebar&quot;&gt;<br>            &lt;h1&gt;Settings&lt;/h1&gt;<br>            &lt;div class=&quot;side-nav&quot;&gt;<br>                &lt;router-link to=&quot;/settings/email&quot;&gt;Email&lt;/router-link&gt;<br>                &lt;router-link to=&quot;/settings/profile&quot;&gt;Profile&lt;/router-link&gt;<br>            &lt;/div&gt;<br>        &lt;/sidebar&gt;<br>        &lt;main class=&quot;main&quot;&gt;<br>            &lt;router-view name=&quot;subscriptions&quot;&gt;&lt;/router-view&gt;<br>            &lt;router-view name=&quot;changeProfile&quot;&gt;&lt;/router-view&gt;<br>            &lt;router-view name=&quot;viewProfile&quot;&gt;&lt;/router-view&gt;<br>        &lt;/main&gt;<br>    &lt;/div&gt;<br>&lt;/template&gt;<br>&lt;script&gt;<br>export default {<br>    name: &#39;Settings&#39;,<br><br>}<br>&lt;/script&gt;<br>&lt;style&gt;<br>*,<br>*::before,<br>*::after {<br>    margin: 0;<br>    padding: 0;<br>    box-sizing: border-box;<br>}<br><br>body {<br>    padding: 0;<br>    margin: 0 !important;<br>}<br><br>.grid {<br>    display: grid;<br>    grid-template-columns: 4fr 8fr;<br>    grid-gap: 20px;<br>}<br><br>.main {<br>    background-color: #fff;<br><br>}<br><br>.sidebar {<br>    background-color: #1c2e4a !important;<br>    color: #fff;<br>    display: flex !important;<br>    flex-direction: column;<br>    /* justify-content: center; */<br>    padding-top: 28px ;<br>    align-items: center;<br>    height: 100vh;<br>}<br>.side-nav{<br>    margin: 16px  0 0 0;<br>}<br><br>a{ <br>    display: block;<br>    color: #fff;<br>    text-decoration: none;<br>    padding: 10px;<br>    font-size: 24px<br>}<br><br>&lt;/style&gt;</pre><p>We are dividing our screen to have a <em>sidebar </em>and <em>main section</em>.</p><p>We are then adding navigation links to the sidebar section to help us navigate to the specified urls segments. We’re using <em>router-link</em> to achieve this.</p><p><em>router-link — allow users to navigate between different views in a Vue.js single-page application (SPA). We specify the path to navigate to using the ‘to’ attribute.</em></p><p>In the main section, we want to display the content of the names views.</p><p>To display multiple views, we are going to use more than one <em>&lt;router-view&gt; component.</em></p><p><em>&lt;router-view&gt; — render the component that matches the current URL route.</em></p><p>If the name attribute is not provided, it displays the default view. to display a specific view, we gave them names and we’ll display then using their names as the value to the <em>name </em>attribute.</p><h4>NOTE — I will not explain the style section as it is made of basic css rules for layout of the page. Feel free to copy and paste as it is.</h4><p>Lastly, let’s change our App.vue file to look like this.</p><pre>&lt;template&gt;<br>    &lt;router-view&gt;&lt;/router-view&gt;<br>&lt;/template&gt;<br>&lt;script&gt;<br>export default {<br>    data() {<br>        return {<br>            message: &#39;Hello from Vue&#39;<br>        }<br>    }<br>}<br>&lt;/script&gt;</pre><p>Go to your browser and refresh the tab where you entered the link and confirm if can see a screen like this:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FK297xoXJBY4%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DK297xoXJBY4&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FK297xoXJBY4%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/65b636e4ba02c5aaa6e28b6599445e77/href">https://medium.com/media/65b636e4ba02c5aaa6e28b6599445e77/href</a></iframe><p>If you didn’t see something close to this, please feel free to start the reading this blog a fresh from the top and never get tired until you get it right.</p><p>Until next time …</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1244eedde756" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Build a dynamic star-rating system using vanilla JavaScript]]></title>
            <link>https://paullasterokoth98.medium.com/build-a-dynamic-star-rating-system-using-vanilla-javascript-d003af09be82?source=rss-3dacee07f8eb------2</link>
            <guid isPermaLink="false">https://medium.com/p/d003af09be82</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[html5]]></category>
            <category><![CDATA[javascript-development]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[css]]></category>
            <dc:creator><![CDATA[Paullaster Okoth]]></dc:creator>
            <pubDate>Fri, 14 Oct 2022 12:07:19 GMT</pubDate>
            <atom:updated>2022-10-14T12:07:19.966Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="unrated 5-star snip" src="https://cdn-images-1.medium.com/max/268/1*cOpHo9mXFoyOOBBikjbClg.png" /></figure><figure><img alt="5-star rating snip" src="https://cdn-images-1.medium.com/max/289/1*CZDpzKCpRbX0Ho-y_Ob4Ig.png" /><figcaption>5-stars</figcaption></figure><h3>Wondering how possible?</h3><p>Now, borrow me your 4 minutes for a ride.</p><p>What you need to know to build this simple system;</p><p><em>html, css, Javascript, DOM manipilation.</em></p><p>We will start by creating a simple html document or page.</p><figure><img alt="simple htm page" src="https://cdn-images-1.medium.com/max/424/1*faXmUCrMapbX3gipJ2rTcw.png" /><figcaption>simple html page</figcaption></figure><p>In this simple html page, apart from the document basic structure, there’s unorder list and list items in it that contains html entity characters for printing a star-shape within the text content of the list items.</p><p>A division to hold the output from user interactions and a script tag that will aid me point to my external javascript file.</p><figure><img alt="html output" src="https://cdn-images-1.medium.com/max/121/1*bRZULEuq0aohy_dYrnKDKg.png" /><figcaption>html output</figcaption></figure><p>our HTML is ready and set for our system.</p><p>Now let’s move quickly and style our page for a better layout and look.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/401/1*JKfeebMITawzw-wfuKpbgA.png" /></figure><p>If you were keen enough, you learnt that we added class attribute to the elements in our html page. I have used classes to style my page as shown in this snippet. I have used html style tag in the head section to style my html page but you may also decide to create an external css and link link using the link element.</p><figure><img alt="output" src="https://cdn-images-1.medium.com/max/277/1*NMyvAsnjIj-72jsT5cJcxQ.png" /><figcaption>Out put of the page after styling</figcaption></figure><p>That said and done, Let’s move to the script for functionality.</p><figure><img alt="js snip" src="https://cdn-images-1.medium.com/max/1024/1*f_EcZ8uq2V0XixLwNLqw5A.png" /><figcaption>js snipped</figcaption></figure><p>On the script above, We only want to perform an action on the page once the DOM content is loaded so we start by listening to the DOMContentLoaded event of the document object.</p><p>Once loaded, It calls my callback function which is passed as an argument to the event listener. In the function <em>ratingStars</em>, we have a for loop that is looping over the html collection of elements with a class of star.</p><p>Notice we are calling a function <em>ratingStarElement </em>in the for loop with <em>length </em>property because we have <em>ratingStarElement</em> function that returns <em>HTMLCollenction </em>which looks like an <em>array </em>and have a <em>length </em>property just like an array and it’s iterable.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/570/1*TJ1soo4ltTg6Go_PKgpbug.png" /></figure><p>Inside the for loop, we are adding an event listener that listen for any click event on each element with a star-shape which invokes a <em>ratingStarClickHander</em> function and binds the arguments when there’s any click action.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/663/1*UlbUAdNfzgAUPAVz4isckw.png" /></figure><p>The function takes two parameters, index and event :-</p><p>index — the position of the li item clicked in the collection (zero based indexing)</p><p>event — action from user, click action for our case.</p><p>The first <em>if statement </em>checks if the event is true — event can only be true when it happened, then we identify the element clicked, we get the parent then get all it’s children , the target element siblings. The parent siblings returns an HTMLCollection.</p><p>We loop through all the childrent and remove the class orange if the have.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/555/1*hxBfipUdxBVSgByvQgA1xw.png" /></figure><p>In the second <em>if statement</em>, we’re checking if the target element clicked does not have a previous sibling — you may not have a previous sibling only if you’re the first.</p><figure><img alt="condition for checking if element is the first child" src="https://cdn-images-1.medium.com/max/663/1*7DjgiAXI2efLx2N7aZ0-YQ.png" /></figure><p>If it’s not the first child, then we’ll add <em>orange </em>class to all the sibling elements that came before the target element and the target element itself.</p><p>Otherwise, we’ll just add the class to the target element alone.</p><p><em>— target element:— this is the html element on which an action occurred.</em></p><figure><img alt="updating index" src="https://cdn-images-1.medium.com/max/346/1*S4TZiBsdsaGUGDpE2nnCqQ.png" /><figcaption>updating index</figcaption></figure><p>Becasue we said that index in the HTMLCollection is 0-based, and rating starts from 1 through 5, we must add 1 to the index of the item that is clicked every time to get the expected result.</p><p>Finaly, We call <em>addTextContent </em>function that takes two arguments: — classname, and text.</p><figure><img alt="addTextContent func" src="https://cdn-images-1.medium.com/max/432/1*F-jzXPtZ1NzsEboQWCWncQ.png" /></figure><figure><img alt="addTextContent func defination" src="https://cdn-images-1.medium.com/max/1024/1*nCgU_AMJmt9aW4gh2sSAHw.png" /></figure><p>This function returns text content added to the HTML element of the specified class and it also invokes another function that returns an html element with a specified class.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/547/1*OOm0Pq4Z979t7uIY0rh8HA.png" /></figure><p>Now were done and we can finaly test our code: —</p><p><a href="https://drive.google.com/file/d/1hchfjeDAzYHWECoSWr56L5Mlo8jD4tC_/view?usp=sharing">Google Drive: Sign-in</a></p><p>Thank you for reading this beginner blog and that’s all I had for you today, until next time.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d003af09be82" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Getting input as a string and returning it’s alphabetical position as the output]]></title>
            <link>https://paullasterokoth98.medium.com/getting-input-as-a-string-and-returning-its-alphabetical-position-as-the-output-5e7f75879afd?source=rss-3dacee07f8eb------2</link>
            <guid isPermaLink="false">https://medium.com/p/5e7f75879afd</guid>
            <category><![CDATA[string-methods]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[string]]></category>
            <category><![CDATA[regular-expressions]]></category>
            <dc:creator><![CDATA[Paullaster Okoth]]></dc:creator>
            <pubDate>Thu, 20 May 2021 22:49:41 GMT</pubDate>
            <atom:updated>2021-05-20T22:54:45.299Z</atom:updated>
            <content:encoded><![CDATA[<p>Hello there,</p><p>Now today is here and I have a small programming task that I will illustrate in JavaScript.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/796/1*PpUc7txyUWCSOu21j1DgCg.png" /><figcaption>Fig 1</figcaption></figure><p>Now, assume that you prompt a user to enter input which must be a string or in other words, must be only contain alphabetical letters otherwise, they get an error. as shown in Fig 2</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/820/1*Y_RR2K2xSz0_rFq8Hyvgew.png" /><figcaption>Fig 2</figcaption></figure><p>I will explain how to write that code in the most simplest way even for a newbie to understand.</p><p>After understanding the requirement of our program, well start writing our code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/995/1*H8bsNz8pHY9vMf39eMbpww.png" /><figcaption>Fig 3</figcaption></figure><p>In Fig 3, I have defined a function called alphabetPosition(usrstr) that take a string as input from user. Then I have defined a variable and assigned it all the 26 alphabetical letters a splitted then into an array.</p><p>I then created another array str, that is updated by the user input.</p><p>NOTE</p><p>user input comes as usrstr the i use the replace() method and RegExp to remove al the white space from the string that user input.</p><p>\s — matches \t, \n and the line</p><p>+— the next one or more</p><p>g — interate the entire input string from the use.</p><p>then covert it to lowercase and the split it into array which become the value of str array.</p><p>Then I am definig an empty numArr that I will use to store the position of the alphabetical letters.</p><p>Looping over the str array and checking if the user input includes the letters in the alphabet array.</p><p>If the condition is true, then push the index +1 of that letter in the alphabet array into the numArr.</p><h3>Why index+1?</h3><blockquote>In programing, the index of array starts from zero. If you are to count the a at index 0 exist at position 1.</blockquote><p>else the user input has any character that is not in the alphabet then they are prompted error.</p><p>The last thing is to return the updated numArr which I join back to a string .</p><p>Thank you so much for reading my post.</p><p>I am Paullaster Okoth</p><p>Developer at Samasource Kenya</p><p><a href="https://github.com/paullaster">Github</a></p><p><a href="https://twitter.com/PaullasterOkoth">Twitter</a></p><p><a href="https://www.linkedin.com/in/paullaster/">LinkedIn</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5e7f75879afd" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>