# Text array and size with function

**URL:** <https://discourse.processing.org/t/text-array-and-size-with-function/37291>\
**Category:** Coding Questions\
**Tags:** homework\
**Created:** [June 2, 2022, 9:08pm UTC](https://discourse.processing.org/t/text-array-and-size-with-function/37291 "2022-06-02T21:08:34Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![luciaromancanivell](https://avatars.discourse-cdn.com/v4/letter/l/8edcca/32.png) [@luciaromancanivell](https://discourse.processing.org/u/luciaromancanivell)\
**Post date:** [June 2, 2022, 9:08pm UTC](https://discourse.processing.org/t/text-array-and-size-with-function/37291/1 "2022-06-02T21:08:34Z")

</div>

Hello,

I am trying to do this…  
 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/8/3/8346a8d287d40de3fb93be3a2c0d6054cfdacd2a.png)  
And I have the following so far… how could I change the width depending on the word?  
so sorry for the many messages, thanks very much!

```auto
var parrafo = "This is big and this small";
var parrafo_array;

function setup() {
	createCanvas(1024, 768);
	background("white");
	fill(50);
	textLeading(25);
	parrafo_array = parrafo.split(' ');
}

function draw () {
    text(parrafo_array, height/2, height/2, textoWidth(palabra));
}

function textoWidth(palabra) {
   if (palabra == 'big') {
   return 400;} 
 
   if (palabra == 'small') {
   return 10;
   }
}

```

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [June 2, 2022, 10:03pm UTC](https://discourse.processing.org/t/text-array-and-size-with-function/37291/2 "2022-06-02T22:03:29Z")

</div>

Hello @luciaromancanivell,

This is a hint only:

```auto
  textSize(24);  
  text(parrafo_array[0], 100, height/2);
  let tw0 = textWidth(parrafo_array[0]); // Text width for this string and textSize()

```

Reference:  
[https://p5js.org/reference/#/p5/textWidth](https://p5js.org/reference/#/p5/textWidth)

> [@luciaromancanivell](#):
>
> how could I change the width depending on the word?

The next word starts at the end of the first word which you have the textWidth() for.

This was the x location for the last word in my code:  
`100+ tw0 + tw1 + tw2 + tw3`

I was able to do this by building on the hint I provided:  
 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/7/a/7af65d5e2c541c7c34e1980240d004c648c426ea.png)

`:)`
